package com.epay.callback;

import cn.hutool.core.util.RandomUtil;
import cn.hutool.crypto.SecureUtil;
import cn.hutool.crypto.symmetric.AES;
import cn.stylefeng.guns.modular.system.entity.Parms;
import cn.stylefeng.guns.modular.system.entity.PlatChannelReport;
import cn.stylefeng.guns.modular.system.entity.PlatMer;
import cn.stylefeng.guns.modular.system.entity.PlatMerOrder;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.epay.Epay;
import com.epay.EpayEncrypt;
import com.epay.RespDataApi;
import com.epay.recharge.RSAUtils;
import com.epay.recharge.RechargeServiceImpl;
import com.epay.service.PlatChannelService;
import com.epay.service.PlatMerOrderService;
import com.epay.service.PlatMerService;
import com.epay.util.DigestUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import sun.misc.BASE64Decoder;

import javax.annotation.Resource;
import javax.crypto.Cipher;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.math.BigDecimal;
import java.security.*;
import java.security.spec.PKCS8EncodedKeySpec;
import java.security.spec.X509EncodedKeySpec;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.TimeUnit;


@Slf4j
@Service
public class PlatMerOrderNotify {


    @Resource
    RedisTemplate redisTemplate;
    @Resource
    PlatMerService platMerService;


    @Resource
    PlatChannelService platChannelService;
    //    @Resource
//    MerOrderFegin merOrderFegin;
    private static final String ALGORITHM = "AES/CBC/PKCS5Padding";

    @Resource
    PlatMerOrderService platMerOrderService;


    public String convertUrlIsEmpty(Map<String, String> map, String join, String eq) {
        StringBuffer url = new StringBuffer();

        for (String result : map.keySet()) {
            url.append(result).append(eq).append(map.get(result)).append(join);

        }

        return url.substring(0, url.toString().length() - 1);

    }

    /**
     * 将map拼接成字符串，空vlaue跳过
     *
     * @param map
     * @param join
     * @param eq
     * @return
     */
    public String convertUrlNotEmpty(Map<String, Object> map, String join, String eq) {
        StringBuilder s = new StringBuilder("");
        for (String key : map.keySet()) {
            if (null != map.get(key) && !"".equals(map.get(key))) {
                s.append(key).append(eq).append(map.get(key)).append(join);
            }
        }
        return s.substring(0, s.toString().length() - 1);
    }

    public String convertUrlNotEmpty(Map<String, Object> map, String eq) {
        StringBuilder s = new StringBuilder("");
        for (String key : map.keySet()) {
            if (null != map.get(key) && !"".equals(map.get(key))) {
                s.append(key).append(eq).append(map.get(key));
            }
        }
        return s.toString();
    }

    private String aesEncrypt(String reqContent, String ivKey) {
        Parms parms = (Parms) redisTemplate.opsForHash().get(Epay.PARAM_KEY, Epay.BaseParams.AES_KEY_CODE);
        String aseKey = parms.getVal();
        return EpayEncrypt.phpAesEncrypt(aseKey, ivKey, reqContent);
    }

    public String convertUrl(Map<String, String> map, String join, String eq) {
        StringBuffer url = new StringBuffer();

        for (String result : map.keySet()) {
            if (!map.containsKey(result) || StringUtils.isEmpty(map.get(result))) {
                continue;
            }
            url.append(result).append(eq).append(map.get(result)).append(join);

        }

        return url.substring(0, url.toString().length() - 1);

    }
    public String convertUrlNotrim(Map<String, String> map, String join, String eq) {
        StringBuffer url = new StringBuffer();

        for (String result : map.keySet()) {
            if (!map.containsKey(result) || StringUtils.isEmpty(map.get(result))) {
                continue;
            }
            url.append(result).append(eq).append(map.get(result)).append(join);

        }

        return url.toString();

    }
    public String convertUrlJoin(Map<String, String> map, String join, String eq) {
        StringBuffer url = new StringBuffer();

        for (String result : map.keySet()) {
            if (!map.containsKey(result) || StringUtils.isEmpty(map.get(result))) {
                continue;
            }
            url.append(result).append(eq).append(map.get(result)).append(join);

        }

        return url.toString();

    }

    public void unlock(String orderId) {
        String key = Epay.RedisKey.PLAT_ORDER_LOCK + orderId;
        redisTemplate.delete(key);


    }

    public boolean lock(String orderId) {
        String key = Epay.RedisKey.PLAT_ORDER_LOCK + orderId;
        Long increment = redisTemplate.opsForValue().increment(key);

        if (increment > 1) {
            return false;
        }
        redisTemplate.expire(key, 30, TimeUnit.SECONDS);


        return true;


    }

    public String jinzhiPay(JSONObject jsonObject) {

        Integer returncode = jsonObject.getInteger("returncode");
        String orderid = jsonObject.getString("orderid");
        double amount = jsonObject.getDouble("amount");
        log.error(" order id " + orderid);
        String sign = jsonObject.getString("sign");
        jsonObject.remove("sign");
        Map sortedMap = new LinkedHashMap();
//amount^0.00&datetime^20180329001741&memberid^YM0001&orderid^152198728788 2&returncode^0&key=345677565t765sasa
        sortedMap.put("amount", jsonObject.getString("amount"));
        sortedMap.put("datetime", jsonObject.getString("datetime"));
        sortedMap.put("memberid", jsonObject.getString("memberid"));
        sortedMap.put("orderid", jsonObject.getString("orderid"));
        sortedMap.put("returncode", jsonObject.getString("returncode"));
        if (returncode.intValue() != 2) {
            log.error("plat order is error  status error" + jsonObject.toJSONString());
            return "plat order is error";
        }
        if (StringUtils.isEmpty(orderid)) {

            log.error("plat order id is empty notify order" + orderid);
            return "plat order  order id is empty";
        }


        try {
            if (!lock(orderid)) {
                return "error";
            }


            PlatMerOrder byOrderId = platMerOrderService.getByOrderId(orderid);

            if (StringUtils.equals(byOrderId.getStat(), "2")) {
                return "SUCCESS";
            }


            double min = byOrderId.getAmount().doubleValue() - 1;
            double max = byOrderId.getAmount().doubleValue() + 1;


            /**
             * 浮动金额
             */
            if (!(amount >= min && amount <= max)) {

//            if (byOrderId.getAmount().doubleValue() != amount) {
                return "amount is  error";
            }

            PlatMer byMerIdCache = platMerService.getByMerIdCache(byOrderId.getMerId());

            if (byMerIdCache == null) {
                return "plat mer is empty not fund";
            }

            String s = convertUrl(sortedMap, "&", "^");


            if (!SecureUtil.md5(s + "&key=" + byMerIdCache.getPrivateKey()).toUpperCase().equals(sign)) {
                return "sign error";
            }

            byOrderId.setRealAmount(new BigDecimal(amount));
            int b = platMerOrderService.success(byOrderId);
            if (b > 0) {


                report(byOrderId);

                return "SUCCESS";
            }
            return "error";

        } catch (RuntimeException ex) {
            log.error("notify EpayException", ex);
            return "error" + ex.getMessage();
        } catch (Exception ex) {
            log.error("notify Exception", ex);
            return "system ex ";
        } finally {
            unlock(orderid);
        }

    }

    public String kaerPay(JSONObject jsonObject) {
        String merchOrder = jsonObject.getString("merchOrder");


        log.error(" order id " + merchOrder);
        Integer status = jsonObject.getInteger("status");
        String sign = jsonObject.getString("sign");
        jsonObject.remove("sign");
        SortedMap sortedMap = new TreeMap();
        for (String key : jsonObject.keySet()) {

            sortedMap.put(key, jsonObject.getString(key));
        }


        if (status.intValue() != 1) {
            log.error("plat order is error" + jsonObject.toJSONString());
            return "plat order status is error";
        }

        if (StringUtils.isEmpty(merchOrder)) {

            log.error("plat order id is empty" + merchOrder);
            return "plat order id is empty";
        }

        try {
            if (!lock(merchOrder)) {
                return "error";
            }


            PlatMerOrder byOrderId = platMerOrderService.getByOrderId(merchOrder);

            if (StringUtils.equals(byOrderId.getStat(), "2")) {
                return "SUCCESS";
            }

            PlatMer byMerIdCache = platMerService.getByMerIdCache(byOrderId.getMerId());

            if (byMerIdCache == null) {
                return "plat mer is empty not fund";
            }

            String s = convertUrl(sortedMap, "&", "=");


            if (!SecureUtil.md5(s + "&key=" + byMerIdCache.getPrivateKey()).toUpperCase().equals(sign)) {
                return "sign error";
            }
            if (byOrderId.getAmount().doubleValue() != jsonObject.getDouble("orderAmount")) {
                return "amount is  error";
            }

            int b = platMerOrderService.success(byOrderId);
            if (b > 0) {


                report(byOrderId);

                return "SUCCESS";
            }
            return "error";

        } catch (RuntimeException ex) {
            log.error("notify EpayException", ex);
            return "error" + ex.getMessage();
        } catch (Exception ex) {
            log.error("notify Exception", ex);
            return "system ex ";
        } finally {
            unlock(merchOrder);
        }


    }

    /**
     * 银付通回调
     *
     * @param jsonObject
     * @return
     */
    public String yinFuTong(JSONObject jsonObject) {
        String merchOrder = jsonObject.getString("orderid");
        String returncode = jsonObject.getString("returncode");
        String sign = jsonObject.getString("sign");
        jsonObject.remove("sign");
        log.error(" order id " + merchOrder);
        SortedMap sortedMap = new TreeMap();
        for (String key : jsonObject.keySet()) {
            sortedMap.put(key, jsonObject.getString(key));
        }

        if (!returncode.equals("00")) {
            log.error("plat order is error" + jsonObject.toJSONString());
            return "plat order is error";
        }
        if (StringUtils.isEmpty(merchOrder)) {
            log.error("plat order id is empty" + merchOrder);
            return "plat order id is empty";
        }
        try {
            if (!lock(merchOrder)) {
                return "error";
            }
            PlatMerOrder byOrderId = platMerOrderService.getByOrderId(merchOrder);
            if (StringUtils.equals(byOrderId.getStat(), "2")) {
                return "OK";
            }
            PlatMer byMerIdCache = platMerService.getByMerIdCache(byOrderId.getMerId());
            if (byMerIdCache == null) {
                return "plat mer is empty not fund";
            }
            String s = convertUrl(sortedMap, "&", "=");

            log.error(" sign url " + s);
            if (!SecureUtil.md5(s + "&key=" + byMerIdCache.getPrivateKey()).toUpperCase().equals(sign)) {
                return "sign error";
            }
            if (byOrderId.getAmount().doubleValue() != jsonObject.getDouble("amount")) {
                return "amount is  error";
            }
            int b = platMerOrderService.success(byOrderId);
            if (b > 0) {
                report(byOrderId);
                log.info("success");
                return "OK";
            }
            return "error";

        } catch (RuntimeException ex) {
            log.error("notify EpayException", ex);
            return "error" + ex.getMessage();
        } catch (Exception ex) {
            log.error("notify Exception", ex);
            return "system ex ";
        } finally {
            unlock(merchOrder);
        }
    }

    public String aqiang(JSONObject jsonObject) {
        String merchOrder = jsonObject.getString("out_trade_no");
        String returncode = "00";
        String sign = jsonObject.getString("sign");
        jsonObject.remove("sign");
        log.error(" order id " + merchOrder);
        SortedMap sortedMap = new TreeMap();
        for (String key : jsonObject.keySet()) {
            sortedMap.put(key, jsonObject.getString(key));
        }

        if (!returncode.equals("00")) {
            log.error("plat order is error" + jsonObject.toJSONString());
            return "plat order is error";
        }
        if (StringUtils.isEmpty(merchOrder)) {
            log.error("plat order id is empty" + merchOrder);
            return "plat order id is empty";
        }
        try {
            if (!lock(merchOrder)) {
                return "error";
            }
            PlatMerOrder byOrderId = platMerOrderService.getByOrderId(merchOrder);
            if (StringUtils.equals(byOrderId.getStat(), "2")) {
                return "success";
            }
            PlatMer byMerIdCache = platMerService.getByMerIdCache(byOrderId.getMerId());
            if (byMerIdCache == null) {
                return "plat mer is empty not fund";
            }
            sortedMap.put("mch_secret", (byMerIdCache.getPrivateKey()));
            String s = convertUrl(sortedMap, "&", "=");
            if (!SecureUtil.md5(s).toUpperCase().equals(sign)) {
                return "sign error";
            }

            if (byOrderId.getAmount().doubleValue() != jsonObject.getDouble("total_fee")) {
                return "amount is  error";
            }
            int b = platMerOrderService.success(byOrderId);
            if (b > 0) {
                report(byOrderId);
                return "success";
            }
            return "error";

        } catch (RuntimeException ex) {
            log.error("notify EpayException", ex);
            return "error" + ex.getMessage();
        } catch (Exception ex) {
            log.error("notify Exception", ex);
            return "system ex ";
        } finally {
            unlock(merchOrder);
        }
    }


    public void report(PlatMerOrder platMerOrder) {
        if (platMerOrder.getMerId() == null) {
            return;
        }
        if (platMerOrder.getPlatMerFee() == null) {
            platMerOrder.setPlatMerFee(new BigDecimal(0));
        }


        PlatChannelReport platChannelReport = new PlatChannelReport();
        platChannelReport.setPlatFee(String.valueOf(platMerOrder.getPlatMerFee().doubleValue()));
        platChannelReport.setChannelCode(platMerOrder.getChannelCode());

        if (platMerOrder.getRealAmount() == null) {


            platChannelReport.setAmount(platMerOrder.getAmount());
        } else {
            platChannelReport.setAmount(platMerOrder.getRealAmount());
        }

        platChannelReport.setTotalAmount(new BigDecimal(0));


        platChannelReport.setChannelMerId(platMerOrder.getMerId());
        platChannelReport.setCreateDate(platMerOrder.getCreatedAt());
        platChannelReport.setReportDate(platMerOrder.getCreatedAt());
        platChannelReport.setPlatCode(platMerOrder.getPlatCode());
        platChannelReport.setChannelMerId(platMerOrder.getMerId());
        platChannelReport.setTotalPlatFee(new BigDecimal(0));
        platChannelReport.setTotalCount(0);
        platChannelReport.setTotalSucceedCount(1);
        platChannelReport.setOrderOrginFee(platMerOrder.getOrginCustFee());
        platChannelService.updateReport(platChannelReport);
    }


    public String tongfu(JSONObject jsonObject) {
        String merchOrder = jsonObject.getString("order_no");
        String returncode = jsonObject.getString("status");
        String sign = jsonObject.getString("sign");
        jsonObject.remove("sign");
        log.error(" order id " + merchOrder);
        SortedMap sortedMap = new TreeMap();
        for (String key : jsonObject.keySet()) {
            sortedMap.put(key, jsonObject.getString(key));
        }

        if (!returncode.equals("1")) {
            log.error("plat order is error" + jsonObject.toJSONString());
            return "plat order is error";
        }
        if (StringUtils.isEmpty(merchOrder)) {
            log.error("plat order id is empty" + merchOrder);
            return "plat order id is empty";
        }
        try {
            if (!lock(merchOrder)) {
                return "error";
            }
            PlatMerOrder byOrderId = platMerOrderService.getByOrderId(merchOrder);
            if (StringUtils.equals(byOrderId.getStat(), "2")) {
                return "success";
            }
            PlatMer byMerIdCache = platMerService.getByMerIdCache(byOrderId.getMerId());
            if (byMerIdCache == null) {
                return "plat mer is empty not fund";
            }
            String s = convertUrl(sortedMap, "&", "=");
            log.info("sign url {}", s);

            log.info("sign url add key {}", s + "&key=" + byMerIdCache.getPrivateKey());
            if (!SecureUtil.md5(s + "&key=" + byMerIdCache.getPrivateKey()).toUpperCase().equals(sign)) {
                return "sign error";
            }

            if (byOrderId.getAmount().doubleValue() != jsonObject.getDouble("amount")) {
                return "amount is  error";
            }
            int b = platMerOrderService.success(byOrderId);
            if (b > 0) {
                report(byOrderId);
                return "success";
            }
            return "error";

        } catch (RuntimeException ex) {
            log.error("notify EpayException", ex);
            return "error" + ex.getMessage();
        } catch (Exception ex) {
            log.error("notify Exception", ex);
            return "system ex ";
        } finally {
            unlock(merchOrder);
        }

    }

    public String huicai(JSONObject jsonObject) {
        String merchOrder = jsonObject.getString("paymentReference");
        String returncode = jsonObject.getString("success");
        String sign = jsonObject.getString("sign");
        jsonObject.remove("sign");
        log.error(" order id " + merchOrder);
        SortedMap sortedMap = new TreeMap();
        for (String key : jsonObject.keySet()) {
            sortedMap.put(key, jsonObject.getString(key));
        }

        if (!returncode.equals("true")) {
            log.error("plat order is error" + jsonObject.toJSONString());
            return "plat order is error";
        }
        if (StringUtils.isEmpty(merchOrder)) {
            log.error("plat order id is empty" + merchOrder);
            return "plat order id is empty";
        }
        try {
            if (!lock(merchOrder)) {
                return "error";
            }
            PlatMerOrder byOrderId = platMerOrderService.getByOrderId(merchOrder);
            if (StringUtils.equals(byOrderId.getStat(), "2")) {
                return "success";
            }
            PlatMer byMerIdCache = platMerService.getByMerIdCache(byOrderId.getMerId());
            if (byMerIdCache == null) {
                return "plat mer is empty not fund";
            }
            String s = convertUrl(sortedMap, "&", "=");
            log.info("sign url {}", s);

            log.info("sign url add key {}", s + "&key=" + byMerIdCache.getPrivateKey());
            if (!SecureUtil.md5(s + "&key=" + byMerIdCache.getPrivateKey()).toUpperCase().equals(sign)) {
                return "sign error";
            }

            if (byOrderId.getAmount().doubleValue() != jsonObject.getDouble("realAmount")) {
                return "amount is  error";
            }
            int b = platMerOrderService.success(byOrderId);
            if (b > 0) {
                report(byOrderId);
                return "success";
            }
            return "error";

        } catch (RuntimeException ex) {
            log.error("notify EpayException", ex);
            return "error" + ex.getMessage();
        } catch (Exception ex) {
            log.error("notify Exception", ex);
            return "system ex ";
        } finally {
            unlock(merchOrder);
        }

    }

    public String mumu(JSONObject jsonObject) {
        String merchOrder = jsonObject.getString("agent_bill_id");
        String returncode = jsonObject.getString("res");
        String sign = jsonObject.getString("sign");
        jsonObject.remove("sign");
        log.error(" order id " + merchOrder);


        if (!returncode.equals("1")) {
            log.error("plat order is error" + jsonObject.toJSONString());
            return "plat order is error";
        }
        if (StringUtils.isEmpty(merchOrder)) {
            log.error("plat order id is empty" + merchOrder);
            return "plat order id is empty";
        }
        try {
            if (!lock(merchOrder)) {
                return "error";
            }
            PlatMerOrder byOrderId = platMerOrderService.getByOrderId(merchOrder);
            if (StringUtils.equals(byOrderId.getStat(), "2")) {
                return "ok";
            }
            PlatMer byMerIdCache = platMerService.getByMerIdCache(byOrderId.getMerId());
            if (byMerIdCache == null) {
                return "plat mer is empty not fund";
            }
            String s = "c_code=" + jsonObject.getString("c_code") + "&pay_type=" + jsonObject.getString("pay_type") + "&pay_amt=" + jsonObject.getString("pay_amt") + "&jpay_bill_id=" + jsonObject.getString("jpay_bill_id") + "&agent_bill_id=" + jsonObject.getString("agent_bill_id") + "&key=" + byMerIdCache.getPrivateKey();
            log.info("sign url {}", s);

            if (!SecureUtil.md5(s).toLowerCase().equals(sign)) {
                return "sign error";
            }

            if (byOrderId.getAmount().doubleValue() != jsonObject.getDouble("pay_amt")) {
                return "amount is  error";
            }
            int b = platMerOrderService.success(byOrderId);
            if (b > 0) {
                report(byOrderId);
                return "ok";
            }
            return "error";

        } catch (RuntimeException ex) {
            log.error("notify EpayException", ex);
            return "error" + ex.getMessage();
        } catch (Exception ex) {
            log.error("notify Exception", ex);
            return "system ex ";
        } finally {
            unlock(merchOrder);
        }

    }

    public String rutong(JSONObject jsonObject) {
        String merchOrder = jsonObject.getString("tradeNo");
        String returncode = jsonObject.getString("state");
        String sign = jsonObject.getString("sign");
        jsonObject.remove("sign");
        log.error(" order id " + merchOrder);
        SortedMap sortedMap = new TreeMap();
        for (String key : jsonObject.keySet()) {
            sortedMap.put(key, jsonObject.getString(key));
        }

        if (!returncode.equals("2001")) {
            log.error("plat order is error" + jsonObject.toJSONString());
            return "plat order is error";
        }
        if (StringUtils.isEmpty(merchOrder)) {
            log.error("plat order id is empty" + merchOrder);
            return "plat order id is empty";
        }
        try {
            if (!lock(merchOrder)) {
                return "error";
            }
            PlatMerOrder byOrderId = platMerOrderService.getByOrderId(merchOrder);
            if (StringUtils.equals(byOrderId.getStat(), "2")) {
                return "success";
            }
            PlatMer byMerIdCache = platMerService.getByMerIdCache(byOrderId.getMerId());
            if (byMerIdCache == null) {
                return "plat mer is empty not fund";
            }
            String s = convertUrl(sortedMap, "&", "=");
            log.info("sign url {}", s);

            log.info("sign url add key {}", s + "&key=" + byMerIdCache.getPrivateKey());
            if (!SecureUtil.md5(s + "&key=" + byMerIdCache.getPrivateKey()).toUpperCase().equals(sign)) {
                return "sign error";
            }
            log.info("sign success {}", merchOrder);
            if ((byOrderId.getAmount().doubleValue() * 100) != (jsonObject.getDouble("actualAmount"))) {

                return "amount is  error";
            }
            int b = platMerOrderService.success(byOrderId);
            if (b > 0) {
                report(byOrderId);
                return "success";
            }
            return "error";

        } catch (RuntimeException ex) {
            log.error("notify EpayException", ex);
            return "error" + ex.getMessage();
        } catch (Exception ex) {
            log.error("notify Exception", ex);
            return "system ex ";
        } finally {
            unlock(merchOrder);
        }

    }

    public String tbdf(JSONObject jsonObject) {
        String merchOrder = jsonObject.getString("order_no");
        String returncode = jsonObject.getString("pay_status");
        String sign = jsonObject.getString("sign");

        jsonObject.remove("sign");
        jsonObject.remove("openid");
        log.error(" order id " + merchOrder);
        SortedMap sortedMap = new TreeMap();
        for (String key : jsonObject.keySet()) {

//            if(StringUtils.isEmpty(jsonObject.getString(key))){
//                continue;
//            }
            sortedMap.put(key, jsonObject.getString(key));
        }

        if (!returncode.equals("1")) {
            log.error("plat order is error" + jsonObject.toJSONString());
            return "plat order is error";
        }
        if (StringUtils.isEmpty(merchOrder)) {
            log.error("plat order id is empty" + merchOrder);
            return "plat order id is empty";
        }
        try {
            if (!lock(merchOrder)) {
                return "error";
            }
            PlatMerOrder byOrderId = platMerOrderService.getByOrderId(merchOrder);
            if (StringUtils.equals(byOrderId.getStat(), "2")) {
                return "success";
            }
            PlatMer byMerIdCache = platMerService.getByMerIdCache(byOrderId.getMerId());
            if (byMerIdCache == null) {
                return "plat mer is empty not fund";
            }
            String s = convertUrlIsEmpty(sortedMap, "&", "=");
            log.info("sign url {}", s);

            log.info("sign url add key {}", s + "&secret=" + byMerIdCache.getPrivateKey());
            if (!SecureUtil.md5(s + "&secret=" + byMerIdCache.getPrivateKey()).toLowerCase().equals(sign)) {
                return "sign error";
            }

            if (byOrderId.getAmount().multiply(new BigDecimal(100)).doubleValue() != (jsonObject.getDouble("actual_amount"))) {
                return "amount is  error";
            }
            int b = platMerOrderService.success(byOrderId);
            if (b > 0) {
                report(byOrderId);
                return "success";
            }
            return "error";

        } catch (RuntimeException ex) {
            log.error("notify EpayException", ex);
            return "error" + ex.getMessage();
        } catch (Exception ex) {
            log.error("notify Exception", ex);
            return "system ex ";
        } finally {
            unlock(merchOrder);
        }


    }

    public String tbdfh5(JSONObject jsonObject) {
        String merchOrder = jsonObject.getString("order_no");
        String returncode = jsonObject.getString("pay_status");
        String sign = jsonObject.getString("sign");

        jsonObject.remove("sign");
        jsonObject.remove("openid");
        log.error(" order id " + merchOrder);
        SortedMap sortedMap = new TreeMap();
        for (String key : jsonObject.keySet()) {

//            if(StringUtils.isEmpty(jsonObject.getString(key))){
//                continue;
//            }
            sortedMap.put(key, jsonObject.getString(key));
        }

        if (!returncode.equals("1")) {
            log.error("plat order is error" + jsonObject.toJSONString());
            return "plat order is error";
        }
        if (StringUtils.isEmpty(merchOrder)) {
            log.error("plat order id is empty" + merchOrder);
            return "plat order id is empty";
        }
        try {
            if (!lock(merchOrder)) {
                return "error";
            }
            PlatMerOrder byOrderId = platMerOrderService.getByOrderId(merchOrder);
            if (StringUtils.equals(byOrderId.getStat(), "2")) {
                return "success";
            }
            PlatMer byMerIdCache = platMerService.getByMerIdCache(byOrderId.getMerId());
            if (byMerIdCache == null) {
                return "plat mer is empty not fund";
            }
            String s = convertUrlIsEmpty(sortedMap, "&", "=");
            log.info("sign url {}", s);

            log.info("sign url add key {}", s + "&secret=" + byMerIdCache.getPrivateKey());
            if (!SecureUtil.md5(s + "&secret=" + byMerIdCache.getPrivateKey()).toLowerCase().equals(sign)) {
                return "sign error";
            }

            if (byOrderId.getAmount().multiply(new BigDecimal(100)).doubleValue() != (jsonObject.getDouble("actual_amount"))) {
                return "amount is  error";
            }
            int b = platMerOrderService.success(byOrderId);
            if (b > 0) {
                report(byOrderId);
                return "success";
            }
            return "error";

        } catch (RuntimeException ex) {
            log.error("notify EpayException", ex);
            return "error" + ex.getMessage();
        } catch (Exception ex) {
            log.error("notify Exception", ex);
            return "system ex ";
        } finally {
            unlock(merchOrder);
        }


    }

    public String thePay(JSONObject jsonObject) {
        String returncode = jsonObject.getString("result");
        String orderid = jsonObject.getString("orderid");
        double amount = jsonObject.getDouble("money");
        log.error(" order id " + orderid);
        String sign = jsonObject.getString("sign");
        jsonObject.remove("sign");
        log.error(" order id " + orderid);


        if (!returncode.equals("Y")) {
            log.error("plat order is error  status error" + jsonObject.toJSONString());
            return "plat order is error is status error";
        }
        if (StringUtils.isEmpty(orderid)) {

            log.error("plat order id is empty notify order" + orderid);
            return "plat order  order id is empty";
        }


        try {
            if (!lock(orderid)) {
                return "error";
            }


            PlatMerOrder byOrderId = platMerOrderService.getByOrderId(orderid);

            if (StringUtils.equals(byOrderId.getStat(), "2")) {
                return "success";
            }


            double min = byOrderId.getAmount().doubleValue() - 1;
            double max = byOrderId.getAmount().doubleValue() + 1;


            /**
             * 浮动金额
             */
            if (!(amount >= min && amount <= max)) {

//            if (byOrderId.getAmount().doubleValue() != amount) {
                return "amount is  error";
            }

            PlatMer byMerIdCache = platMerService.getByMerIdCache(byOrderId.getMerId());

            if (byMerIdCache == null) {
                return "plat mer is empty not fund";
            }

            String s = "result=" + jsonObject.getString("result") + "&memberid=" + jsonObject.getString("memberid") + "&orderid=" + jsonObject.getString("orderid") + "&money=" + jsonObject.getString("money") + "&date=" + jsonObject.getString("date") + byMerIdCache.getPrivateKey();
            log.error("result sign {}", s);

            if (!SecureUtil.md5(s).toLowerCase().equals(sign)) {
                return "sign error";
            }

            byOrderId.setRealAmount(new BigDecimal(amount));
            int b = platMerOrderService.success(byOrderId);
            if (b > 0) {


                report(byOrderId);

                return "success";
            }
            return "error";

        } catch (RuntimeException ex) {
            log.error("notify EpayException", ex);
            return "error" + ex.getMessage();
        } catch (Exception ex) {
            log.error("notify Exception", ex);
            return "system ex ";
        } finally {
            unlock(orderid);
        }
    }


    public String aopay(JSONObject jsonObject) {
        log.info("json {}", jsonObject);
//        String returncode = jsonObject.getString("result");
        String orderid = jsonObject.getString("out_trade_no");
        double amount = jsonObject.getDouble("order_money");
        log.error(" order id " + orderid);
        String sign = jsonObject.getString("sign");
        jsonObject.remove("sign");
        log.error(" order id " + orderid);


//        if (!returncode.equals("Y")) {
//            log.error("plat order is error  status error" + jsonObject.toJSONString());
//            return "plat order is error is status error";
//        }
        if (StringUtils.isEmpty(orderid)) {

            log.error("plat order id is empty notify order" + orderid);
            return "plat order  order id is empty";
        }


        try {
            if (!lock(orderid)) {
                return "error";
            }


            PlatMerOrder byOrderId = platMerOrderService.getByOrderId(orderid);

            if (StringUtils.equals(byOrderId.getStat(), "2")) {
                return "Success";
            }


            double min = byOrderId.getAmount().doubleValue() - 1;
            double max = byOrderId.getAmount().doubleValue() + 1;


            /**
             * 浮动金额
             */
            if (!(amount >= min && amount <= max)) {

//            if (byOrderId.getAmount().doubleValue() != amount) {
                return "amount is  error";
            }

            PlatMer byMerIdCache = platMerService.getByMerIdCache(byOrderId.getMerId());

            if (byMerIdCache == null) {
                return "plat mer is empty not fund";
            }

            String s = "merchantNo=" + jsonObject.getString("merchantNo") + "&money=" + jsonObject.getString("money") + "&order_money=" + jsonObject.getString("order_money") + "&order_num=" + jsonObject.getString("order_num") + "&out_trade_no=" + jsonObject.getString("out_trade_no") + "&secret=" + byMerIdCache.getPrivateKey();
            log.error("result sign {}", s);

            if (!SecureUtil.md5(s).toUpperCase().equals(sign)) {

                log.error(" sigin error {}", jsonObject.toJSONString());
                return "sign error";
            }

            byOrderId.setRealAmount(new BigDecimal(amount));
            int b = platMerOrderService.success(byOrderId);
            if (b > 0) {


                report(byOrderId);

                return "Success";
            }
            return "error";

        } catch (RuntimeException ex) {
            log.error("notify EpayException", ex);
            return "error" + ex.getMessage();
        } catch (Exception ex) {
            log.error("notify Exception", ex);
            return "system ex ";
        } finally {
            unlock(orderid);
        }
    }

    public String aapay(JSONObject jsonObject) {


//        String returncode = jsonObject.getString("result");
        String orderid = jsonObject.getString("mOrderNo");
        double amount = jsonObject.getDouble("pay");
        log.error(" order id " + orderid);
        String sign = jsonObject.getString("sign");
        jsonObject.remove("sign");
        log.error(" order id " + orderid);
        if (!jsonObject.containsKey("account")) {

            jsonObject.put("account", "");
        }

        SortedMap sortedMap = new TreeMap();
        for (String key : jsonObject.keySet()) {
            sortedMap.put(key, jsonObject.getString(key));
        }


//        if (!returncode.equals("Y")) {
//            log.error("plat order is error  status error" + jsonObject.toJSONString());
//            return "plat order is error is status error";
//        }
        if (StringUtils.isEmpty(orderid)) {

            log.error("plat order id is empty notify order" + orderid);
            return "plat order  order id is empty";
        }


        try {
            if (!lock(orderid)) {
                return "error";
            }


            PlatMerOrder byOrderId = platMerOrderService.getByOrderId(orderid);

            if (StringUtils.equals(byOrderId.getStat(), "2")) {
                return "success";
            }


            if (byOrderId.getAmount().doubleValue() * 100 != (jsonObject.getDouble("pay"))) {
                return "amount is  error";
            }

            PlatMer byMerIdCache = platMerService.getByMerIdCache(byOrderId.getMerId());

            if (byMerIdCache == null) {
                return "plat mer is empty not fund";
            }

            String s = convertUrlIsEmpty(sortedMap, "&", "=");
            log.info("sign url {}", s);

            log.info("sign url add key {}", s + "&key=" + byMerIdCache.getPrivateKey());
            if (!SecureUtil.md5(s + "&key=" + byMerIdCache.getPrivateKey()).toLowerCase().equals(sign)) {
                return "sign error";
            }

            int b = platMerOrderService.success(byOrderId);
            if (b > 0) {


                report(byOrderId);

                return "success";
            }
            return "error";

        } catch (RuntimeException ex) {
            log.error("notify EpayException", ex);
            return "error" + ex.getMessage();
        } catch (Exception ex) {
            log.error("notify Exception", ex);
            return "system ex ";
        } finally {
            unlock(orderid);
        }
    }

    public String binli(JSONObject jsonObject) {

        String merchOrder = jsonObject.getString("orderid");
        String returncode = jsonObject.getString("returncode");
        String sign = jsonObject.getString("sign");
        jsonObject.remove("sign");
        jsonObject.remove("attach");
        log.error(" order id " + merchOrder);
        SortedMap sortedMap = new TreeMap();
        for (String key : jsonObject.keySet()) {
            sortedMap.put(key, jsonObject.getString(key));
        }

        if (!returncode.equals("00")) {
            log.error("plat order is error" + jsonObject.toJSONString());
            return "plat order is error";
        }
        if (StringUtils.isEmpty(merchOrder)) {
            log.error("plat order id is empty" + merchOrder);
            return "plat order id is empty";
        }
        try {
            if (!lock(merchOrder)) {
                return "error";
            }
            PlatMerOrder byOrderId = platMerOrderService.getByOrderId(merchOrder);
            if (StringUtils.equals(byOrderId.getStat(), "2")) {
                return "OK";
            }
            PlatMer byMerIdCache = platMerService.getByMerIdCache(byOrderId.getMerId());
            if (byMerIdCache == null) {
                return "plat mer is empty not fund";
            }
            String s = convertUrlIsEmpty(sortedMap, "&", "=");
            log.info("sign url {}", s);

            log.info("sign url add key {}", s + "&key=" + byMerIdCache.getPrivateKey());
            if (!SecureUtil.md5(s + "&key=" + byMerIdCache.getPrivateKey()).toUpperCase().equals(sign)) {
                return "sign error";
            }

            if (byOrderId.getAmount().doubleValue() != (jsonObject.getDouble("amount"))) {
                return "amount is  error";
            }
            int b = platMerOrderService.success(byOrderId);
            if (b > 0) {
                report(byOrderId);
                return "OK";
            }
            return "error";

        } catch (RuntimeException ex) {
            log.error("notify EpayException", ex);
            return "error" + ex.getMessage();
        } catch (Exception ex) {
            log.error("notify Exception", ex);
            return "system ex ";
        } finally {
            unlock(merchOrder);
        }
    }

    public String mingdongzfUrl(JSONObject jsonObject) {

        String merchOrder = jsonObject.getString("out_trade_no");
        String returncode = jsonObject.getString("return_code");
        String sign = jsonObject.getString("sign");
        jsonObject.remove("sign");
        log.error(" order id " + merchOrder);
        SortedMap sortedMap = new TreeMap();
        for (String key : jsonObject.keySet()) {
            sortedMap.put(key, jsonObject.getString(key));
        }

        if (!returncode.equals("SUCCESS")) {
            log.error("plat order is error" + jsonObject.toJSONString());
            return "plat order is error";
        }
        if (StringUtils.isEmpty(merchOrder)) {
            log.error("plat order id is empty" + merchOrder);
            return "plat order id is empty";
        }
        try {
            if (!lock(merchOrder)) {
                return "error";
            }
            PlatMerOrder byOrderId = platMerOrderService.getByOrderId(merchOrder);
            if (StringUtils.equals(byOrderId.getStat(), "2")) {
                return "success";
            }
            PlatMer byMerIdCache = platMerService.getByMerIdCache(byOrderId.getMerId());
            if (byMerIdCache == null) {
                return "plat mer is empty not fund";
            }
            String s = convertUrlIsEmpty(sortedMap, "&", "=");
            log.info("sign url {}", s);

            log.info("sign url add key {}", s + "&key=" + byMerIdCache.getPrivateKey());
            if (!SecureUtil.md5(s + "&key=" + byMerIdCache.getPrivateKey()).toUpperCase().equals(sign)) {
                return "sign error";
            }

            if (byOrderId.getAmount().doubleValue() != (jsonObject.getDouble("amount"))) {
                return "amount is  error";
            }
            int b = platMerOrderService.success(byOrderId);
            if (b > 0) {
                report(byOrderId);
                return "success";
            }
            return "error";

        } catch (RuntimeException ex) {
            log.error("notify EpayException", ex);
            return "error" + ex.getMessage();
        } catch (Exception ex) {
            log.error("notify Exception", ex);
            return "system ex ";
        } finally {
            unlock(merchOrder);
        }
    }

    public String bajie(JSONObject jsonObject) {


        String merchOrder = jsonObject.getString("order_id");
        String returncode = jsonObject.getString("status");
        String sign = jsonObject.getString("sign");
        jsonObject.remove("sign");
        log.error(" order id " + merchOrder);
        SortedMap sortedMap = new TreeMap();
        for (String key : jsonObject.keySet()) {
            sortedMap.put(key, jsonObject.getString(key));
        }

        if (!returncode.equals("1")) {
            log.error("plat order is error" + jsonObject.toJSONString());
            return "plat order is error";
        }
        if (StringUtils.isEmpty(merchOrder)) {
            log.error("plat order id is empty" + merchOrder);
            return "plat order id is empty";
        }
        try {
            if (!lock(merchOrder)) {
                return "error";
            }
            PlatMerOrder byOrderId = platMerOrderService.getByOrderId(merchOrder);
            if (StringUtils.equals(byOrderId.getStat(), "2")) {
                return "success";
            }
            PlatMer byMerIdCache = platMerService.getByMerIdCache(byOrderId.getMerId());
            if (byMerIdCache == null) {
                return "plat mer is empty not fund";
            }
            String s = convertUrlIsEmpty(sortedMap, "&", "=");
            log.info("sign url {}", s);

            log.info("sign url add key {}", s + "&key=" + byMerIdCache.getPrivateKey());
            if (!SecureUtil.md5(s + "&key=" + byMerIdCache.getPrivateKey()).toUpperCase().equals(sign)) {
                return "sign error";
            }

            if (byOrderId.getAmount().doubleValue() != (jsonObject.getDouble("total_fee"))) {
                return "amount is  error";
            }
            int b = platMerOrderService.success(byOrderId);
            if (b > 0) {
                report(byOrderId);
                return "success";
            }
            return "error";

        } catch (RuntimeException ex) {
            log.error("notify EpayException", ex);
            return "error" + ex.getMessage();
        } catch (Exception ex) {
            log.error("notify Exception", ex);
            return "system ex ";
        } finally {
            unlock(merchOrder);
        }
    }

    public String NEWSP(JSONObject jsonObject) {
        String merchOrder = jsonObject.getString("out_trade_no");
        String returncode = "00";
        String sign = jsonObject.getString("sign");
        jsonObject.remove("sign");
        log.error(" order id " + merchOrder);
        SortedMap sortedMap = new TreeMap();
        for (String key : jsonObject.keySet()) {
            sortedMap.put(key, jsonObject.getString(key));
        }

        if (!returncode.equals("00")) {
            log.error("plat order is error" + jsonObject.toJSONString());
            return "plat order is error";
        }
        if (StringUtils.isEmpty(merchOrder)) {
            log.error("plat order id is empty" + merchOrder);
            return "plat order id is empty";
        }
        try {
            if (!lock(merchOrder)) {
                return "error";
            }
            PlatMerOrder byOrderId = platMerOrderService.getByOrderId(merchOrder);
            if (StringUtils.equals(byOrderId.getStat(), "2")) {
                return "Success";
            }
            PlatMer byMerIdCache = platMerService.getByMerIdCache(byOrderId.getMerId());
            if (byMerIdCache == null) {
                return "plat mer is empty not fund";
            }
            String s = convertUrlIsEmpty(sortedMap, "&", "=");
            log.info("sign url {}", s);

            log.info("sign url add key {}", s + "&secret=" + byMerIdCache.getPrivateKey());
            if (!SecureUtil.md5(s + "&secret=" + byMerIdCache.getPrivateKey()).toUpperCase().equals(sign)) {
                return "sign error";
            }

            if (byOrderId.getAmount().doubleValue() != jsonObject.getDouble("order_money")) {
                return "amount is  error";
            }
            int b = platMerOrderService.success(byOrderId);
            if (b > 0) {
                report(byOrderId);
                return "Success";
            }
            return "error";

        } catch (RuntimeException ex) {
            log.error("notify EpayException", ex);
            return "error" + ex.getMessage();
        } catch (Exception ex) {
            log.error("notify Exception", ex);
            return "system ex ";
        } finally {
            unlock(merchOrder);
        }
    }

    public String jinpayUrl(JSONObject jsonObject) {


        return yinFuTong(jsonObject);
    }

    public String jufu(JSONObject jsonObject) {
        String merchOrder = jsonObject.getString("outOrderNo");
        String returncode = jsonObject.getString("status");
        String sign = jsonObject.getString("signature");
        jsonObject.remove("signaturede");
        log.error(" order id " + merchOrder);
        SortedMap sortedMap = new TreeMap();
        for (String key : jsonObject.keySet()) {
            sortedMap.put(key, jsonObject.getString(key));
        }

        if (!returncode.equals("SUCCESS")) {
            log.error("plat order is error" + jsonObject.toJSONString());
            return "plat order is error";
        }
        if (StringUtils.isEmpty(merchOrder)) {
            log.error("plat order id is empty" + merchOrder);
            return "plat order id is empty";
        }
        try {
            if (!lock(merchOrder)) {
                return "error";
            }
            PlatMerOrder byOrderId = platMerOrderService.getByOrderId(merchOrder);
            if (StringUtils.equals(byOrderId.getStat(), "2")) {
                return "SUCCESS";
            }
            PlatMer byMerIdCache = platMerService.getByMerIdCache(byOrderId.getMerId());
            if (byMerIdCache == null) {
                return "plat mer is empty not fund";
            }
            String s = "?amount=" + byOrderId.getAmount().intValue() + "" + "&attach=test88&outOrderNo=" + byOrderId.getOrderId() + "&payType=" + jsonObject.getString("payType") + "" + byMerIdCache.getMerKey() + "" + jsonObject.getString("timestamp") + "" + jsonObject.getString("nonceStr");
            log.info("sign url {}", s);
            s = SecureUtil.md5(s).toLowerCase() + byMerIdCache.getPrivateKey();

            log.error("sign url  md5" + s);
            if (!SecureUtil.md5(s).toUpperCase().equals(sign)) {
                return "sign error";
            }

            if (byOrderId.getAmount().doubleValue() != jsonObject.getDouble("money")) {
                return "amount is  error";
            }
            int b = platMerOrderService.success(byOrderId);
            if (b > 0) {
                report(byOrderId);
                return "SUCCESS";
            }
            return "error";

        } catch (RuntimeException ex) {
            log.error("notify EpayException", ex);
            return "error" + ex.getMessage();
        } catch (Exception ex) {
            log.error("notify Exception", ex);
            return "system ex ";
        } finally {
            unlock(merchOrder);
        }
    }


    public String mywechat(JSONObject jsonObject) {
        log.error("json error {}", jsonObject.toJSONString());
        String key = jsonObject.getString("key");
        String account = jsonObject.getString("account");
        BigDecimal amount = jsonObject.getBigDecimal("amount");
        Parms myKey = (Parms) redisTemplate.opsForHash().get(Epay.PARAM_KEY, "wechatKey");
        if (!key.equals(myKey.getVal())) {

            log.error("key is error mywechat" + jsonObject.toJSONString());
            return "key is error mywechat";
        }

        String merchOrder = account + amount;
        try {

            if (!lock(merchOrder)) {
                return "error";
            }
            JSONObject jsonObjectResult = new JSONObject();

            jsonObjectResult.put("channelCode", jsonObject.get("channelCode"));
            jsonObjectResult.put("amount", amount);
            jsonObjectResult.put("account", account);

            String iv = RandomUtil.randomNumbers(16);
            Parms aes = (Parms) redisTemplate.opsForHash().get(Epay.PARAM_KEY, Epay.BaseParams.AES_KEY_CODE);
            String reqParam = EpayEncrypt.phpAesEncrypt(aes.getVal(), iv, jsonObjectResult.toJSONString());
            RespDataApi<String> respDataApi = platMerOrderService.arrByAmountMerCode(reqParam, iv);
            log.error("update order is info {}", respDataApi.toString());
            if (respDataApi.getCode().intValue() == 200) {


                PlatMerOrder byOrderId = platMerOrderService.getByOrderId(respDataApi.getData());
                log.error("byorder" + byOrderId);
                if (StringUtils.equals(byOrderId.getStat(), "2")) {
                    return "SUCCESS";
                }


//            LambdaUpdateWrapper<PlatMerOrder> lambdaUpdateWrapper = new LambdaUpdateWrapper<PlatMerOrder>();
//
//            lambdaUpdateWrapper.eq(PlatMerOrder::getOrderId, byOrderId.getOrderId());
//            lambdaUpdateWrapper.set(PlatMerOrder::getStat, EpayTransfer.OrderStat.ARRIVED);
//
//            lambdaUpdateWrapper.set(PlatMerOrder::getSuccessDate,new Date());
//


                boolean update = platMerOrderService.updateMyWechat(byOrderId.getOrderId(), byOrderId.getRealAmount());

                if (update) {

                    report(byOrderId);
                    return "SUCCESS";
                }
            }

            return "error";

        } catch (RuntimeException ex) {
            log.error("notify EpayException", ex);
            return "error" + ex.getMessage();
        } catch (Exception ex) {
            log.error("notify Exception", ex);
            return "system ex ";
        } finally {
            unlock(merchOrder);
        }

    }

    public String jinair(JSONObject jsonObject) {
        String returncode = jsonObject.getString("result");
        String orderid = jsonObject.getString("out_trade_no");
        double amount = jsonObject.getDouble("order_money");
        log.error(" order id " + orderid);
        String sign = jsonObject.getString("sign");
        jsonObject.remove("sign");
        log.error(" order id " + orderid);


//        if (!returncode.equals("Y")) {
//            log.error("plat order is error  status error" + jsonObject.toJSONString());
//            return "plat order is error is status error";
//        }
        if (StringUtils.isEmpty(orderid)) {

            log.error("plat order id is empty notify order" + orderid);
            return "plat order  order id is empty";
        }


        try {
            if (!lock(orderid)) {
                return "error";
            }


            PlatMerOrder byOrderId = platMerOrderService.getByOrderId(orderid);

            if (StringUtils.equals(byOrderId.getStat(), "2")) {
                return "Success";
            }


            double min = byOrderId.getAmount().doubleValue() - 1;
            double max = byOrderId.getAmount().doubleValue() + 1;


            /**
             * 浮动金额
             */
            if (!(amount >= min && amount <= max)) {

//            if (byOrderId.getAmount().doubleValue() != amount) {
                return "amount is  error";
            }

            PlatMer byMerIdCache = platMerService.getByMerIdCache(byOrderId.getMerId());

            if (byMerIdCache == null) {
                return "plat mer is empty not fund";
            }

            String s = "merchantNo=" + jsonObject.getString("merchantNo") + "&money=" + jsonObject.getString("money") + "&order_money=" + jsonObject.getString("order_money") + "&order_num=" + jsonObject.getString("order_num") + "&out_trade_no=" + jsonObject.getString("out_trade_no") + "&secret=" + byMerIdCache.getPrivateKey();
            log.error("result sign {}", s);

            if (!SecureUtil.md5(s).toUpperCase().equals(sign)) {

                log.error(" sigin error {}", jsonObject.toJSONString());
                return "sign error";
            }

            byOrderId.setRealAmount(new BigDecimal(amount));
            int b = platMerOrderService.success(byOrderId);
            if (b > 0) {


                report(byOrderId);

                return "Success";
            }
            return "error";

        } catch (RuntimeException ex) {
            log.error("notify EpayException", ex);
            return "error" + ex.getMessage();
        } catch (Exception ex) {
            log.error("notify Exception", ex);
            return "system ex ";
        } finally {
            unlock(orderid);
        }
    }

    public String taohaoPay(JSONObject jsonObject) {
        String merchOrder = jsonObject.getString("shop_no");


        log.error(" order id " + merchOrder);
        Integer status = jsonObject.getInteger("status");
        String sign = jsonObject.getString("sign");
        jsonObject.remove("sign");
        SortedMap sortedMap = new TreeMap();
        for (String key : jsonObject.keySet()) {

            sortedMap.put(key, jsonObject.getString(key));
        }


        if (status.intValue() != 0) {
            log.error("plat order is error" + jsonObject.toJSONString());
            return "plat order status is error";
        }

        if (StringUtils.isEmpty(merchOrder)) {

            log.error("plat order id is empty" + merchOrder);
            return "plat order id is empty";
        }

        try {
            if (!lock(merchOrder)) {
                return "error";
            }


            PlatMerOrder byOrderId = platMerOrderService.getByOrderId(merchOrder);

            if (StringUtils.equals(byOrderId.getStat(), "2")) {
                return "SUCCESS";
            }

            PlatMer byMerIdCache = platMerService.getByMerIdCache(byOrderId.getMerId());

            if (byMerIdCache == null) {
                return "plat mer is empty not fund";
            }

            String s = byMerIdCache.getMerKey() + "&" + jsonObject.getString("status") + "&" + jsonObject.get("trade_no") + "&" + jsonObject.getString("shop_no") + "&" + jsonObject.getString("money") + "&" + jsonObject.getString("type") + "&";


            if (!SecureUtil.md5(s + byMerIdCache.getPrivateKey()).toLowerCase().equals(sign)) {
                return "sign error";
            }


            if (byOrderId.getAmount().doubleValue() != jsonObject.getDouble("money")) {
                return "amount is  error";
            }

            int b = platMerOrderService.success(byOrderId);
            if (b > 0) {


                report(byOrderId);

                return "SUCCESS";
            }
            return "error";

        } catch (RuntimeException ex) {
            log.error("notify EpayException", ex);
            return "error" + ex.getMessage();
        } catch (Exception ex) {
            log.error("notify Exception", ex);
            return "system ex ";
        } finally {
            unlock(merchOrder);
        }


    }

    public String sanfangUrl(JSONObject jsonObject) {

        String merchOrder = jsonObject.getString("mchOrderNo");


        log.error(" order id " + merchOrder);
        Integer status = jsonObject.getInteger("resultCode");
        String sign = jsonObject.getString("sign");

        //message
        jsonObject.remove("sign");
        SortedMap sortedMap = new TreeMap();
        for (String key : jsonObject.keySet()) {

            sortedMap.put(key, jsonObject.getString(key));
        }


        if (status.intValue() != 0) {
            log.error("plat order is error" + jsonObject.toJSONString());
            return "plat order status is error";
        }

        if (StringUtils.isEmpty(merchOrder)) {

            log.error("plat order id is empty" + merchOrder);
            return "plat order id is empty";
        }

        try {
            if (!lock(merchOrder)) {
                return "error";
            }


            PlatMerOrder byOrderId = platMerOrderService.getByOrderId(merchOrder);

            if (StringUtils.equals(byOrderId.getStat(), "2")) {
                return "success";
            }

            PlatMer byMerIdCache = platMerService.getByMerIdCache(byOrderId.getMerId());

            if (byMerIdCache == null) {
                return "plat mer is empty not fund";
            }

//            String s = byMerIdCache.getMerKey()+"&"+jsonObject.getString("status")+"&"+jsonObject.get("trade_no")+"&"+jsonObject.getString("shop_no")+"&"+jsonObject.getString("money")+"&"+jsonObject.getString("type")+"&";
            String s = convertUrl(sortedMap, "&", "=");

            log.error("sanfang  {}", s);

            if (!SecureUtil.md5(s + "&paySecret=" + byMerIdCache.getPrivateKey()).toUpperCase().equals(sign)) {
                return "sign error";
            }


            if ((byOrderId.getAmount().doubleValue()*100) != jsonObject.getDouble("amount")) {
                return "amount is  error";
            }

            int b = platMerOrderService.success(byOrderId);
            if (b > 0) {


                report(byOrderId);

                return "success";
            }
            return "error";

        } catch (RuntimeException ex) {
            log.error("notify EpayException", ex);
            return "error" + ex.getMessage();
        } catch (Exception ex) {
            log.error("notify Exception", ex);
            return "system ex ";
        } finally {
            unlock(merchOrder);
        }

    }

    public String jinfuhui(JSONObject jsonObject) {

        String merchOrder = jsonObject.getString("sdorderno");


        log.error(" order id " + merchOrder);
        Integer status = jsonObject.getInteger("status");
        String sign = jsonObject.getString("sign");

        //message
        jsonObject.remove("sign");
        SortedMap sortedMap = new TreeMap();
        for (String key : jsonObject.keySet()) {

            sortedMap.put(key, jsonObject.getString(key));
        }


        if (status.intValue() != 1) {
            log.error("plat order is error" + jsonObject.toJSONString());
            return "plat order status is error";
        }

        if (StringUtils.isEmpty(merchOrder)) {

            log.error("plat order id is empty" + merchOrder);
            return "plat order id is empty";
        }

        try {
            if (!lock(merchOrder)) {
                return "error";
            }


            PlatMerOrder byOrderId = platMerOrderService.getByOrderId(merchOrder);

            if (StringUtils.equals(byOrderId.getStat(), "2")) {
                return "success";
            }

            PlatMer byMerIdCache = platMerService.getByMerIdCache(byOrderId.getMerId());

            if (byMerIdCache == null) {
                return "plat mer is empty not fund";
            }

            String s = "customerid=" + jsonObject.get("customerid") + "&status=" + jsonObject.get("status") + "&sdpayno=" + jsonObject.get("sdpayno") + "&sdorderno=" + jsonObject.get("sdorderno") + "&total_fee=" + jsonObject.get("total_fee") + "&paytype=" + jsonObject.get("paytype") + "&" + byMerIdCache.getPrivateKey();
            log.error("huijinfu  {}", s);

            if (!SecureUtil.md5(s).toLowerCase().equals(sign)) {
                return "sign error";
            }


            if (byOrderId.getAmount().doubleValue() != jsonObject.getDouble("total_fee")) {
                return "amount is  error";
            }

            int b = platMerOrderService.success(byOrderId);
            if (b > 0) {


                report(byOrderId);

                return "success";
            }
            return "error";

        } catch (RuntimeException ex) {
            log.error("notify EpayException", ex);
            return "error" + ex.getMessage();
        } catch (Exception ex) {
            log.error("notify Exception", ex);
            return "system ex ";
        } finally {
            unlock(merchOrder);
        }

    }

    public String otc(JSONObject jsonObject) {

        String merchOrder = jsonObject.getString("orderid");


        log.error(" order id " + merchOrder);
        String sign = jsonObject.getString("sign");

        //message
        jsonObject.remove("sign");
        SortedMap sortedMap = new TreeMap();
        for (String key : jsonObject.keySet()) {

            sortedMap.put(key, jsonObject.getString(key));
        }


        if (StringUtils.isEmpty(merchOrder)) {

            log.error("plat order id is empty" + merchOrder);
            return "plat order id is empty";
        }

        try {
            if (!lock(merchOrder)) {
                return "error";
            }


            PlatMerOrder byOrderId = platMerOrderService.getByOrderId(merchOrder);

            if (StringUtils.equals(byOrderId.getStat(), "2")) {
                return "0";
            }

            PlatMer byMerIdCache = platMerService.getByMerIdCache(byOrderId.getMerId());

            if (byMerIdCache == null) {
                return "plat mer is empty not fund";
            }
            String s = convertUrl(sortedMap, "&", "=") + "&key=" + byMerIdCache.getPrivateKey();
            log.error("otc  {}", s);
            s = SecureUtil.md5(s).toLowerCase();

            if (!s.toLowerCase().equals(sign)) {
                return "sign error";
            }


            if (byOrderId.getAmount().doubleValue() != jsonObject.getDouble("rmb")) {
                return "amount is  error";
            }

            int b = platMerOrderService.success(byOrderId);
            if (b > 0) {


                report(byOrderId);

                return "0";
            }
            return "error";

        } catch (RuntimeException ex) {
            log.error("notify EpayException", ex);
            return "error" + ex.getMessage();
        } catch (Exception ex) {
            log.error("notify Exception", ex);
            return "system ex ";
        } finally {
            unlock(merchOrder);
        }

    }

    public String tianxie(JSONObject jsonObject) {

        return yinFuTong(jsonObject);
    }

    public String jxpay(JSONObject jsonObject) {

        return yinFuTong(jsonObject);
    }

    public String kkpay(JSONObject jsonObject) {

        return yinFuTong(jsonObject);
    }

    public String qfb(JSONObject jsonObject) {

        String merchOrder = jsonObject.getString("orderid");


        log.error(" order id " + merchOrder);
        Integer status = jsonObject.getInteger("opstate");
        String sign = jsonObject.getString("sign");

        //message
        jsonObject.remove("sign");
        SortedMap sortedMap = new TreeMap();
        for (String key : jsonObject.keySet()) {

            sortedMap.put(key, jsonObject.getString(key));
        }


        if (status.intValue() != 0) {
            log.error("plat order is error" + jsonObject.toJSONString());
            return "plat order status is error";
        }

        if (StringUtils.isEmpty(merchOrder)) {

            log.error("plat order id is empty" + merchOrder);
            return "plat order id is empty";
        }

        try {
            if (!lock(merchOrder)) {
                return "error";
            }


            PlatMerOrder byOrderId = platMerOrderService.getByOrderId(merchOrder);

            if (StringUtils.equals(byOrderId.getStat(), "2")) {
                return "opstate=0";
            }

            PlatMer byMerIdCache = platMerService.getByMerIdCache(byOrderId.getMerId());

            if (byMerIdCache == null) {
                return "plat mer is empty not fund";
            }

            String s = "orderid=" + jsonObject.getString("orderid") + "&opstate=" + jsonObject.getString("opstate") + "&ovalue=" + jsonObject.getString("ovalue") + byMerIdCache.getPrivateKey();
            log.info("result a qbf {}", s);
//            String sign = SecureUtil.md5(s +"&"+ byMerIdCache.getPrivateKey()).toLowerCase();

            if (!SecureUtil.md5(s).toLowerCase().equals(sign)) {
                return "sign error";
            }


            if (byOrderId.getAmount().doubleValue() != jsonObject.getDouble("ovalue")) {
                return "amount is  error";
            }

            int b = platMerOrderService.success(byOrderId);
            if (b > 0) {


                report(byOrderId);

                return "opstate=0";
            }
            return "error";

        } catch (RuntimeException ex) {
            log.error("notify EpayException", ex);
            return "error" + ex.getMessage();
        } catch (Exception ex) {
            log.error("notify Exception", ex);
            return "system ex ";
        } finally {
            unlock(merchOrder);
        }

    }

    public String fp(JSONObject jsonObject) {

        String merchOrder = jsonObject.getString("fxddh");


        log.error(" order id " + merchOrder);
        Integer status = jsonObject.getInteger("fxstatus");
        String sign = jsonObject.getString("fxsign");

        //message
        jsonObject.remove("sign");
        SortedMap sortedMap = new TreeMap();
        for (String key : jsonObject.keySet()) {

            sortedMap.put(key, jsonObject.getString(key));
        }


        if (status.intValue() != 1) {
            log.error("plat order is error" + jsonObject.toJSONString());
            return "plat order status is error";
        }

        if (StringUtils.isEmpty(merchOrder)) {

            log.error("plat order id is empty" + merchOrder);
            return "plat order id is empty";
        }

        try {
            if (!lock(merchOrder)) {
                return "error";
            }


            PlatMerOrder byOrderId = platMerOrderService.getByOrderId(merchOrder);

            if (StringUtils.equals(byOrderId.getStat(), "2")) {
                return "success";
            }

            PlatMer byMerIdCache = platMerService.getByMerIdCache(byOrderId.getMerId());

            if (byMerIdCache == null) {
                return "plat mer is empty not fund";
            }

            String s = (jsonObject.getString("fxstatus") + jsonObject.getString("fxid") + jsonObject.getString("fxddh") + jsonObject.getString("fxfee") + byMerIdCache.getPrivateKey());
//            String sign = SecureUtil.md5(s +"&"+ byMerIdCache.getPrivateKey()).toLowerCase();
            log.error(" sign url error {}", s);
            if (!SecureUtil.md5(s).toLowerCase().equals(sign)) {
                return "sign error";
            }


            if (byOrderId.getAmount().doubleValue() != jsonObject.getDouble("fxfee")) {
                return "amount is  error";
            }

            int b = platMerOrderService.success(byOrderId);
            if (b > 0) {


                report(byOrderId);

                return "success";
            }
            return "error";

        } catch (RuntimeException ex) {
            log.error("notify EpayException", ex);
            return "error" + ex.getMessage();
        } catch (Exception ex) {
            log.error("notify Exception", ex);
            return "system ex ";
        } finally {
            unlock(merchOrder);
        }

    }

    public String xgpay(JSONObject jsonObject) {

        return fp(jsonObject);

    }

    public String xingguan(JSONObject jsonObject) {

        String merchOrder = jsonObject.getString("fxddh");


        log.error(" order id " + merchOrder);
        Integer status = jsonObject.getInteger("fxstatus");
        String sign = jsonObject.getString("fxsign");

        //message
        jsonObject.remove("sign");
        SortedMap sortedMap = new TreeMap();
        for (String key : jsonObject.keySet()) {

            sortedMap.put(key, jsonObject.getString(key));
        }


        if (status.intValue() != 1) {
            log.error("plat order is error" + jsonObject.toJSONString());
            return "plat order status is error";
        }

        if (StringUtils.isEmpty(merchOrder)) {

            log.error("plat order id is empty" + merchOrder);
            return "plat order id is empty";
        }

        try {
            if (!lock(merchOrder)) {
                return "error";
            }


            PlatMerOrder byOrderId = platMerOrderService.getByOrderId(merchOrder);

            if (StringUtils.equals(byOrderId.getStat(), "2")) {
                return "success";
            }

            PlatMer byMerIdCache = platMerService.getByMerIdCache(byOrderId.getMerId());

            if (byMerIdCache == null) {
                return "plat mer is empty not fund";
            }

            String s = (jsonObject.getString("fxstatus") + jsonObject.getString("fxid") + jsonObject.getString("fxddh") + jsonObject.getString("fxfee") + byMerIdCache.getPrivateKey());
//            String sign = SecureUtil.md5(s +"&"+ byMerIdCache.getPrivateKey()).toLowerCase();
            log.error(" sign url error {}", s);
            if (!SecureUtil.md5(s).toLowerCase().equals(sign)) {
                return "sign error";
            }


            if (byOrderId.getAmount().doubleValue() != jsonObject.getDouble("fxfee")) {
                return "amount is  error";
            }

            int b = platMerOrderService.success(byOrderId);
            if (b > 0) {


                report(byOrderId);

                return "success";
            }
            return "error";

        } catch (RuntimeException ex) {
            log.error("notify EpayException", ex);
            return "error" + ex.getMessage();
        } catch (Exception ex) {
            log.error("notify Exception", ex);
            return "system ex ";
        } finally {
            unlock(merchOrder);
        }

    }

    public String dongyating(JSONObject jsonObject) {

        return yinFuTong(jsonObject);

    }

    public String dongyayihao(JSONObject jsonObject) {

        String merchOrder = jsonObject.getString("sh_order");


        String sign = jsonObject.getString("sign");

        //message
        jsonObject.remove("sign");
        SortedMap sortedMap = new TreeMap();
        for (String key : jsonObject.keySet()) {

            sortedMap.put(key, jsonObject.getString(key));
        }


        if (StringUtils.isEmpty(merchOrder)) {

            log.error("plat order id is empty" + merchOrder);
            return "plat order id is empty";
        }

        try {
            if (!lock(merchOrder)) {
                return "error";
            }


            PlatMerOrder byOrderId = platMerOrderService.getByOrderId(merchOrder);

            if (StringUtils.equals(byOrderId.getStat(), "2")) {
                return "success";
            }

            PlatMer byMerIdCache = platMerService.getByMerIdCache(byOrderId.getMerId());

            if (byMerIdCache == null) {
                return "plat mer is empty not fund";
            }

            String s = convertUrl(sortedMap, "&", "=") + "&key=" + byMerIdCache.getPrivateKey();
//            String sign = SecureUtil.md5(s +"&"+ byMerIdCache.getPrivateKey()).toLowerCase();
            log.error(" sign url error {}", s);
            if (!SecureUtil.md5(s).toLowerCase().equals(sign)) {
                return "sign error";
            }


            if (byOrderId.getAmount().doubleValue() != jsonObject.getDouble("money")) {
                return "amount is  error";
            }

            int b = platMerOrderService.success(byOrderId);
            if (b > 0) {


                report(byOrderId);

                return "success";
            }
            return "error";

        } catch (RuntimeException ex) {
            log.error("notify EpayException", ex);
            return "error" + ex.getMessage();
        } catch (Exception ex) {
            log.error("notify Exception", ex);
            return "system ex ";
        } finally {
            unlock(merchOrder);
        }
    }

    public String xiaoshi003Url(JSONObject jsonObject) {
        log.info("xiaoshi003 jsonObject" + jsonObject);

        String orderId = jsonObject.getString("api_order_sn");
        String status = jsonObject.getString("callbacks");
        String sign = jsonObject.getString("sign");
        log.info(String.format("orderId=%s, status=%s, sign=%s", orderId, status, sign));
        jsonObject.remove("sign");
        SortedMap sortedMap = new TreeMap();
        for (String key : jsonObject.keySet()) {

            sortedMap.put(key, jsonObject.getString(key));
        }

        if ("CODE_SUCCESS".equals(status)) {

            if (!StringUtils.isEmpty(orderId)) {

                try {

                    if (!lock(orderId)) {
                        log.error("xiaoshi003 is lock");
                        return "error";
                    }

                    PlatMerOrder order = platMerOrderService.getByOrderId(orderId);
                    if (StringUtils.equals(order.getStat(), "2")) {
                        log.info("xiaoshi003 order ok");
                        return "success";
                    }

                    PlatMer byMerIdCache = platMerService.getByMerIdCache(order.getMerId());
                    if (byMerIdCache == null) {
                        log.info("xiaoshi003 order ok plat mer is empty not fund");
                        return "plat mer is empty not fund";
                    }


                    String s = byMerIdCache.getPrivateKey() + convertUrlJoin(sortedMap, "", "") + byMerIdCache.getPrivateKey();
                    log.info("xiaoshi003 callback s " + s);
                    log.info("xiaoshi003 callback md5(s) " + s);

                    if (SecureUtil.md5(s).toUpperCase().equals(sign)) {

                        if (order.getAmount().doubleValue() == jsonObject.getDouble("total")) {

                            int b = platMerOrderService.success(order);

                            if (b > 0) {
                                report(order);
                                return "success";
                            } else {
                                log.error("xiaoshi003 callback error");
                                return "xiaoshi003 callback error";
                            }

                        } else {
                            log.error("xiaoshi003 callback amount is error");
                            return "xiaoshi003 callback amount is error";
                        }

                    } else {
                        log.error("xiaoshi003 callback sign error");
                        return "xiaoshi003 callback sign error";
                    }

                } catch (RuntimeException ex) {
                    log.error("xiaoshi003 callback notify EpayException", ex);
                    return "xiaoshi003 callback error" + ex.getMessage();
                } catch (Exception ex) {
                    log.error("xiaoshi003 callback notify Exception", ex);
                    return "xiaoshi003 callback system ex ";
                } finally {
                    unlock(orderId);
                }

            } else {
                log.error("xiaoshi003 callback plat order id is empty" + orderId);
                return "xiaoshi003 callback plat order id is empty";
            }

        } else {
            log.error("xiaoshi003 callback plat order is error" + jsonObject.toJSONString());
            return "xiaoshi003 callback plat order status is error";
        }

    }

    public String baolai(JSONObject jsonObject) {

        String merchOrder = jsonObject.getString("Trans_Id");

        Integer status = jsonObject.getInteger("Status");
        String sign = jsonObject.getString("Sign");

        //message
        jsonObject.remove("Sign");

        if (status.intValue() != 1) {
            log.error("plat order is error" + jsonObject.toJSONString());
            return "plat order status is error";
        }


        if (StringUtils.isEmpty(merchOrder)) {

            log.error("plat order id is empty" + merchOrder);
            return "plat order id is empty";
        }

        try {
            if (!lock(merchOrder)) {
                return "error";
            }


            PlatMerOrder byOrderId = platMerOrderService.getByOrderId(merchOrder);

            if (StringUtils.equals(byOrderId.getStat(), "2")) {
                return "success";
            }

            PlatMer byMerIdCache = platMerService.getByMerIdCache(byOrderId.getMerId());

            if (byMerIdCache == null) {
                return "plat mer is empty not fund";
            }

            String s = byMerIdCache.getPrivateKey() + jsonObject.getString("User") + jsonObject.getString("Trans_Id");
            log.error(" sign url error {}", s);
            s = SecureUtil.md5(s).toLowerCase() + jsonObject.getString("Order_Id") + jsonObject.getString("Order_Time") + jsonObject.getString("Status") + jsonObject.getString("Amount");
            log.error(" sign url error {}", s);
//            String sign = SecureUtil.md5(s +"&"+ byMerIdCache.getPrivateKey()).toLowerCase();
            log.error(" sign url error {}", s);
            if (!SecureUtil.md5(s).toLowerCase().equals(sign)) {
                return "sign error";
            }


            if (byOrderId.getAmount().doubleValue() != jsonObject.getDouble("Amount")) {
                return "amount is  error";
            }

            int b = platMerOrderService.success(byOrderId);
            if (b > 0) {


                report(byOrderId);

                return "success";
            }
            return "error";

        } catch (RuntimeException ex) {
            log.error("notify EpayException", ex);
            return "error" + ex.getMessage();
        } catch (Exception ex) {
            log.error("notify Exception", ex);
            return "system ex ";
        } finally {
            unlock(merchOrder);
        }
    }

    public String hngmpay(JSONObject jsonObject) {

        return pilinUrl(jsonObject);
    }

    public String pilinUrl(JSONObject jsonObject) {
        log.info("pilin jsonObject " + jsonObject);
        String orderId = jsonObject.getString("out_trade_no");
        String status = jsonObject.getString("callbacks");
        String sign = jsonObject.getString("sign");
        log.info(String.format("orderId=%s, status=%s, sign=%s", orderId, status, sign));

        if ("CODE_SUCCESS".equals(status)) {

            if (!StringUtils.isEmpty(orderId)) {

                try {

                    if (!lock(orderId)) {
                        log.error("pilin is lock");
                        return "error";
                    }

                    PlatMerOrder order = platMerOrderService.getByOrderId(orderId);
                    if (StringUtils.equals(order.getStat(), "2")) {
                        return "success";
                    }

                    PlatMer byMerIdCache = platMerService.getByMerIdCache(order.getMerId());
                    if (byMerIdCache == null) {
                        return "plat mer is empty not fund";
                    }

                    jsonObject.remove("sign");
                    Map<String, String> map = new TreeMap<>();
                    for (String key : jsonObject.keySet()) {
                        if (null != jsonObject.get(key) && !"".equals(jsonObject.get(key))) {
                            map.put(key, jsonObject.get(key).toString());
                        }
                    }
                    String s = convertUrl(map, "&", "=") + "&key=" + byMerIdCache.getPrivateKey();
                    String md5Str = SecureUtil.md5(s);
                    log.info("s " + s);
                    log.info("md5(s) " + md5Str);

                    if (md5Str.toUpperCase().equals(sign)) {

                        if (order.getAmount().doubleValue() == jsonObject.getDouble("amount_true")) {

                            int b = platMerOrderService.success(order);

                            if (b > 0) {
                                report(order);
                                log.info("ok");
                                return "success";
                            } else {
                                log.error("error");
                                return "error";
                            }

                        } else {
                            log.error("amount is error");
                            return "amount is error";
                        }

                    } else {
                        log.error("sign error");
                        return "sign error";
                    }

                } catch (RuntimeException ex) {
                    log.error("notify EpayException", ex);
                    return "error" + ex.getMessage();
                } catch (Exception ex) {
                    log.error("notify Exception", ex);
                    return "system ex ";
                } finally {
                    unlock(orderId);
                }

            } else {
                log.error("plat order id is empty" + orderId);
                return "plat order id is empty";
            }

        } else {
            log.error("plat order is error" + jsonObject.toJSONString());
            return "plat order status is error";
        }

    }

    public String happyxyb(JSONObject jsonObject) {

        return hongyiUrl(jsonObject);
    }

    public String hongyiUrl(JSONObject jsonObject) {
        String orderId = jsonObject.getString("ordernumber");
        String status = jsonObject.getString("orderstatus");
        String sign = jsonObject.getString("sign");
        log.info(String.format("orderId=%s, status=%s, sign=%s", orderId, status, sign));

        if ("1".equals(status)) {

            if (!StringUtils.isEmpty(orderId)) {

                try {

                    if (!lock(orderId)) {
                        log.error("hongYi is lock");
                        return "error";
                    }

                    PlatMerOrder order = platMerOrderService.getByOrderId(orderId);
                    if (StringUtils.equals(order.getStat(), "2")) {
                        log.info("hongyi success");
                        return "success";
                    }

                    PlatMer byMerIdCache = platMerService.getByMerIdCache(order.getMerId());
                    if (byMerIdCache == null) {
                        log.info("hongyi plat mer is empty not fund");
                        return "plat mer is empty not fund";
                    }

                    String s = "partner=" + jsonObject.getString("partner") + "&ordernumber=" + jsonObject.getString("ordernumber") +
                            "&orderstatus=" + status + "&paymoney=" + jsonObject.getString("paymoney") + "&sysnumber=" + jsonObject.getString("sysnumber") +
                            byMerIdCache.getPrivateKey();
                    String md5Str = SecureUtil.md5(s);
                    log.info("hongYi s " + s);
                    log.info("hongYi md5(s) " + md5Str);

                    if (md5Str.toLowerCase().equals(sign)) {

                        if (order.getAmount().doubleValue() == jsonObject.getDouble("paymoney")) {

                            int b = platMerOrderService.success(order);

                            if (b > 0) {
                                report(order);
                                log.info("hongyi callback success");
                                return "ok";
                            } else {
                                log.error("error");
                                return "error";
                            }

                        } else {
                            log.error("amount is error");
                            return "amount is error";
                        }

                    } else {
                        log.error("sign error");
                        return "sign error";
                    }

                } catch (RuntimeException ex) {
                    log.error("notify EpayException", ex);
                    return "error" + ex.getMessage();
                } catch (Exception ex) {
                    log.error("notify Exception", ex);
                    return "system ex ";
                } finally {
                    unlock(orderId);
                }

            } else {
                log.error("plat order id is empty" + orderId);
                return "plat order id is empty";
            }

        } else {
            log.error("plat order is error" + jsonObject.toJSONString());
            return "plat order status is error";
        }

    }

    public String dingUrl(JSONObject jsonObject) {
        log.info("ding callback jsonObject " + jsonObject);
        String orderId = jsonObject.getString("mchOrderNo");
        String status = jsonObject.getString("status");
        String sign = jsonObject.getString("sign");
        log.info(String.format("ding callback orderId=%s, status=%s, sign=%s", orderId, status, sign));

//        if ("2".equals(status)) {
            if (true) {
            if (!StringUtils.isEmpty(orderId)) {

                try {

                    if (!lock(orderId)) {
                        log.error("ding callback is lock");
                        return "error";
                    }

                    PlatMerOrder order = platMerOrderService.getByOrderId(orderId);
                    if (StringUtils.equals(order.getStat(), "2")) {
                        log.info("ding callback order success");
                        return "success";
                    }

                    PlatMer byMerIdCache = platMerService.getByMerIdCache(order.getMerId());
                    if (byMerIdCache == null) {
                        log.info("ding callback plat mer is empty not fund");
                        return "plat mer is empty not fund";
                    }

                    jsonObject.remove("sign");
                    SortedMap sortedMap = new TreeMap();
                    for (String key : jsonObject.keySet()) {
                        sortedMap.put(key, jsonObject.getString(key));
                    }
                    String s = convertUrlNotEmpty(sortedMap, "&", "=") + "&key=" + byMerIdCache.getPrivateKey();
                    String md5Str = SecureUtil.md5(s).toUpperCase();

                    log.info("hongYi s " + s);
                    log.info("hongYi md5(s) " + md5Str);

                    if (md5Str.equals(sign)) {

                        if (order.getAmount().doubleValue() == (jsonObject.getDouble("amount") / 100)) {

                            int b = platMerOrderService.success(order);

                            if (b > 0) {
                                log.info("ding launch success");

                                report(order);
                                log.info("success");
                                return "success";
                            } else {
                                log.error("ding callback error");
                                return "error";
                            }

                        } else {
                            log.error("ding callback amount is error");
                            return "amount is error";
                        }

                    } else {
                        log.error("ding callback sign error");
                        return "sign error";
                    }

                } catch (RuntimeException ex) {
                    log.error("ding callback notify EpayException", ex);
                    return "error" + ex.getMessage();
                } catch (Exception ex) {
                    log.error("ding callback notify Exception", ex);
                    return "system ex ";
                } finally {
                    unlock(orderId);
                }

            } else {
                log.error("ding callback plat order id is empty" + orderId);
                return "plat order id is empty";
            }

        } else {
            log.error("ding callback plat order is error" + jsonObject.toJSONString());
            return "plat order status is error";
        }

    }

    public String jinxinUrl(JSONObject jsonObject) {
        log.info("jinxin callback jsonObject " + jsonObject);
        String orderId = jsonObject.getString("mchOrderNo");
        String status = jsonObject.getString("status");
        String sign = jsonObject.getString("sign");
        log.info(String.format("jinxin callback orderId=%s, status=%s, sign=%s", orderId, status, sign));

        if ("2".equals(status)) {
            if (!StringUtils.isEmpty(orderId)) {

                try {

                    if (!lock(orderId)) {
                        log.error("jinxin callback is lock");
                        return "error";
                    }

                    PlatMerOrder order = platMerOrderService.getByOrderId(orderId);
                    if (StringUtils.equals(order.getStat(), "2")) {
                        log.info("jinxin callback order success");
                        return "success";
                    }

                    PlatMer byMerIdCache = platMerService.getByMerIdCache(order.getMerId());
                    if (byMerIdCache == null) {
                        log.info("jinxin callback plat mer is empty not fund");
                        return "plat mer is empty not fund";
                    }

                    jsonObject.remove("sign");
                    SortedMap sortedMap = new TreeMap();
                    for (String key : jsonObject.keySet()) {
                        sortedMap.put(key, jsonObject.getString(key));
                    }
                    String s = convertUrlNotEmpty(sortedMap, "&", "=") + "&key=" + byMerIdCache.getPrivateKey();
                    String md5Str = SecureUtil.md5(s).toUpperCase();

                    log.info("hongYi s " + s);
                    log.info("hongYi md5(s) " + md5Str);

                    if (md5Str.equals(sign)) {

                        if (order.getAmount().doubleValue() == (jsonObject.getDouble("amount") / 100)) {

                            int b = platMerOrderService.success(order);

                            if (b > 0) {
                                log.info("jinxin launch success");

                                report(order);
                                log.info("success");
                                return "success";
                            } else {
                                log.error("jinxin callback error");
                                return "error";
                            }

                        } else {
                            log.error("jinxin callback amount is error");
                            return "amount is error";
                        }

                    } else {
                        log.error("jinxin callback sign error");
                        return "sign error";
                    }

                } catch (RuntimeException ex) {
                    log.error("jinxin callback notify EpayException", ex);
                    return "error" + ex.getMessage();
                } catch (Exception ex) {
                    log.error("jinxin callback notify Exception", ex);
                    return "system ex ";
                } finally {
                    unlock(orderId);
                }

            } else {
                log.error("jinxin callback plat order id is empty" + orderId);
                return "plat order id is empty";
            }

        } else {
            log.error("jinxin callback plat order is error" + jsonObject.toJSONString());
            return "plat order status is error";
        }

    }
    
    public String yuanwangUrl(JSONObject jsonObject) {
        log.info("yuanwang callback jsonObject " + jsonObject);
        String orderId = jsonObject.getString("bill_id");
        String status = jsonObject.getString("code");
        String sign = jsonObject.getString("sign");
        log.info(String.format("yuanwang callback orderId=%s, status=%s, sign=%s", orderId, status, sign));
        if ("1".equals(status)) {

            if (!StringUtils.isEmpty(orderId)) {

                try {

                    if (!lock(orderId)) {
                        log.error("yuanwang callback is lock");
                        return "error";
                    }

                    PlatMerOrder order = platMerOrderService.getByOrderId(orderId);
                    if (StringUtils.equals(order.getStat(), "2")) {
                        log.info("yuanwang callback order success");
                        return "SUCCESS";
                    }

                    PlatMer byMerIdCache = platMerService.getByMerIdCache(order.getMerId());
                    if (byMerIdCache == null) {
                        log.info("yuanwang callback plat mer is empty not fund");
                        return "plat mer is empty not fund";
                    }

                    jsonObject.remove("sign");
                    SortedMap sortedMap = new TreeMap();
                    for (String key : jsonObject.keySet()) {
                        sortedMap.put(key, jsonObject.getString(key));
                    }
                    String s = convertUrlIsEmpty(sortedMap, "&", "=") + "&mch_key=" + byMerIdCache.getPrivateKey();
                    String md5Str = SecureUtil.md5(s);

                    log.info("yuanwang s " + s);
                    log.info("yuanwang md5(s) " + md5Str);

                    if (md5Str.equals(sign)) {

                        if (order.getAmount().doubleValue() == jsonObject.getDouble("amount")) {

                            int b = platMerOrderService.success(order);

                            if (b > 0) {
                                report(order);
                                log.info("yuanwang callback success");
                                return "SUCCESS";
                            } else {
                                log.error("yuanwang callback error");
                                return "error";
                            }

                        } else {
                            log.error("yuanwang callback amount is error");
                            return "amount is error";
                        }

                    } else {
                        log.error("yuanwang callback sign error");
                        return "sign error";
                    }

                } catch (RuntimeException ex) {
                    log.error("yuanwang callback notify EpayException", ex);
                    return "error" + ex.getMessage();
                } catch (Exception ex) {
                    log.error("yuanwang callback notify Exception", ex);
                    return "system ex ";
                } finally {
                    unlock(orderId);
                }

            } else {
                log.error("yuanwang callback plat order id is empty" + orderId);
                return "plat order id is empty";
            }

        } else {
            log.error("yuanwang callback plat order is error" + jsonObject.toJSONString());
            return "plat order status is error";
        }

    }

    public String upayUrl(JSONObject jsonObject) {
        log.info("upayUrl callback jsonObject " + jsonObject);
        String orderId = jsonObject.getString("merchantBizNum");
        String status = jsonObject.getString("status");
        String sign = jsonObject.getString("sign");
        log.info(String.format("upayUrl callback orderId=%s, status=%s, sign=%s", orderId, status, sign));

        if ("1".equals(status)) {

            if (!StringUtils.isEmpty(orderId)) {

                try {

                    if (!lock(orderId)) {
                        log.error("upayUrl callback is lock");
                        return "error";
                    }

                    PlatMerOrder order = platMerOrderService.getByOrderId(orderId);
                    if (StringUtils.equals(order.getStat(), "2")) {
                        log.info("upayUrl callback order success");
                        return "success";
                    }

                    PlatMer byMerIdCache = platMerService.getByMerIdCache(order.getMerId());
                    if (byMerIdCache == null) {
                        log.info("upayUrl callback plat mer is empty not fund");
                        return "plat mer is empty not fund";
                    }

                    String s = "merchantBizNum=" + jsonObject.get("merchantBizNum") + "&merchantId=" + jsonObject.getString("merchantId") + "&merchantPrice=" + jsonObject.getString("merchantPrice") +
                            "&money=" + jsonObject.getString("money") + "&status=" + jsonObject.get("status") + "&sysBizNum=" +
                            jsonObject.getString("sysBizNum") + "&usdtAmount=" + jsonObject.getString("usdtAmount") +
                            "&key=" + byMerIdCache.getPrivateKey();
                    String md5Str = SecureUtil.md5(s).toUpperCase();

                    log.info("ΩUrl s " + s);
                    log.info("upayUrl md5(s) " + md5Str);

                    if (md5Str.equals(sign)) {

                        if ((order.getAmount().multiply(new BigDecimal(100)).doubleValue()) == jsonObject.getDouble("money").doubleValue()) {

                            int b = platMerOrderService.success(order);

                            if (b > 0) {
                                report(order);
                                log.info("upayUrl callback success");
                                return "success";
                            } else {
                                log.error("upayUrl callback error");
                                return "error";
                            }

                        } else {
                            log.error("upayUrl callback amount is error");
                            return "amount is error";
                        }

                    } else {
                        log.error("upayUrl callback sign error");
                        return "sign error";
                    }

                } catch (RuntimeException ex) {
                    log.error("upayUrl callback notify EpayException", ex);
                    return "error" + ex.getMessage();
                } catch (Exception ex) {
                    log.error("upayUrl callback notify Exception", ex);
                    return "system ex ";
                } finally {
                    unlock(orderId);
                }

            } else {
                log.error("upayUrl callback plat order id is empty" + orderId);
                return "plat order id is empty";
            }

        } else {
            log.error("upayUrl callback plat order is error" + jsonObject.toJSONString());
            return "plat order status is error";
        }

    }

    public String basecodUrl(JSONObject jsonObject) {
        log.info("basecodUrl callback jsonObject " + jsonObject);
        String orderId = jsonObject.getString("no_order");
        String status = jsonObject.getString("result_pay");
        String sign = jsonObject.getString("sign");
        log.info(String.format("basecod callback orderId=%s, status=%s, sign=%s", orderId, status, sign));

        if ("SUCCESS".equals(status)) {

            if (!StringUtils.isEmpty(orderId)) {

                try {

                    if (!lock(orderId)) {
                        log.error("basecod callback is lock");
                        return "error";
                    }

                    PlatMerOrder order = platMerOrderService.getByOrderId(orderId);
                    if (StringUtils.equals(order.getStat(), "2")) {
                        log.info("basecod callback order success");
                        return "success";
                    }

                    PlatMer byMerIdCache = platMerService.getByMerIdCache(order.getMerId());
                    if (byMerIdCache == null) {
                        log.info("basecod callback plat mer is empty not fund");
                        return "basecod plat mer is empty not fund";
                    }

                    jsonObject.remove("sign");
                    SortedMap sortedMap = new TreeMap();
                    for (String key : jsonObject.keySet()) {
                        sortedMap.put(key, jsonObject.getString(key));
                    }
                    String s = convertUrlNotEmpty(sortedMap, "&", "=") + byMerIdCache.getPrivateKey();
                    String md5Str = SecureUtil.md5(s);

                    log.info("basecod s " + s);
                    log.info("basecod md5(s) " + md5Str);

                    if (md5Str.equals(sign)) {

                        if (order.getAmount().doubleValue() == jsonObject.getDouble("money_order")) {

                            int b = platMerOrderService.success(order);

                            if (b > 0) {
                                report(order);
                                log.info("basecod callback success");
                                return "success";
                            } else {
                                log.error("basecod callback error");
                                return "error";
                            }

                        } else {
                            log.error("basecod callback amount is error");
                            return "amount is error";
                        }

                    } else {
                        log.error("basecod callback sign error");
                        return "sign error";
                    }

                } catch (RuntimeException ex) {
                    log.error("basecod callback notify EpayException", ex);
                    return "error" + ex.getMessage();
                } catch (Exception ex) {
                    log.error("basecod callback notify Exception", ex);
                    return "system ex ";
                } finally {
                    unlock(orderId);
                }

            } else {
                log.error("basecod callback plat order id is empty" + orderId);
                return "plat order id is empty";
            }

        } else {
            log.error("basecod callback plat order is error" + jsonObject.toJSONString());
            return "plat order status is error";
        }
    }

    public String xiaozhoutongUrl(JSONObject jsonObject) {
        log.info("xiaozhoutong callback jsonObject " + jsonObject);
        String orderId = jsonObject.getString("out_trade_no");
        String status = jsonObject.getString("trade_status");
        String sign = jsonObject.getString("sign");
        log.info(String.format("xiaozhoutong callback orderId=%s, status=%s, sign=%s", orderId, status, sign));
        if ("TRADE_SUCCESS".equals(status)) {

            if (!StringUtils.isEmpty(orderId)) {

                try {

                    if (!lock(orderId)) {
                        log.error("xiaozhoutong callback is lock");
                        return "error";
                    }

                    PlatMerOrder order = platMerOrderService.getByOrderId(orderId);
                    if (StringUtils.equals(order.getStat(), "2")) {
                        log.info("xiaozhoutong callback order success");
                        return "success";
                    }

                    PlatMer byMerIdCache = platMerService.getByMerIdCache(order.getMerId());
                    if (byMerIdCache == null) {
                        log.info("xiaozhoutong callback plat mer is empty not fund");
                        return "plat mer is empty not fund";
                    }

                    jsonObject.remove("sign");
                    jsonObject.remove("sign_type");
                    SortedMap sortedMap = new TreeMap();
                    for (String key : jsonObject.keySet()) {
                        sortedMap.put(key, jsonObject.getString(key));
                    }
                    String s = convertUrlIsEmpty(sortedMap, "&", "=") + byMerIdCache.getPrivateKey();
                    String md5Str = SecureUtil.md5(s);

                    log.info("xiaozhoutong s " + s);
                    log.info("xiaozhoutong md5(s) " + md5Str);

                    if (md5Str.equals(sign)) {

                        if (order.getAmount().doubleValue() == jsonObject.getDouble("money")) {

                            int b = platMerOrderService.success(order);

                            if (b > 0) {
                                report(order);
                                log.info("xiaozhoutong callback success");
                                return "success";
                            } else {
                                log.error("xiaozhoutong callback error");
                                return "error";
                            }

                        } else {
                            log.error("xiaozhoutong callback amount is error");
                            return "amount is error";
                        }

                    } else {
                        log.error("xiaozhoutong callback sign error");
                        return "sign error";
                    }

                } catch (RuntimeException ex) {
                    log.error("xiaozhoutong callback notify EpayException", ex);
                    return "error" + ex.getMessage();
                } catch (Exception ex) {
                    log.error("xiaozhoutong callback notify Exception", ex);
                    return "system ex ";
                } finally {
                    unlock(orderId);
                }

            } else {
                log.error("xiaozhoutong callback plat order id is empty" + orderId);
                return "plat order id is empty";
            }

        } else {
            log.error("xiaozhoutong callback plat order is error" + jsonObject.toJSONString());
            return "plat order status is error";
        }

    }

    public String gxyxUrl(JSONObject param) {


        return dongyayihao(param);
    }

    public String caiyingUrl(JSONObject param) {

        return dongyayihao(param);
    }

    public String qmpayUrl(JSONObject jsonObject) {
        log.info("qmpay callback jsonObject " + jsonObject);
        String orderId = jsonObject.getString("transNumber");
        String status = jsonObject.getString("payStatus");
        String sign = jsonObject.getString("sign");
        log.info(String.format("qmpay callback orderId=%s, status=%s, sign=%s", orderId, status, sign));
        if ("1".equals(status)) {

            if (!StringUtils.isEmpty(orderId)) {

                try {

                    if (!lock(orderId)) {
                        log.error("qmpay callback is lock");
                        return "error";
                    }

                    PlatMerOrder order = platMerOrderService.getByOrderId(orderId);
                    if (StringUtils.equals(order.getStat(), "2")) {
                        log.info("qmpay callback order success");
                        return "success";
                    }

                    PlatMer byMerIdCache = platMerService.getByMerIdCache(order.getMerId());
                    if (byMerIdCache == null) {
                        log.info("qmpay callback plat mer is empty not fund");
                        return "plat mer is empty not fund";
                    }

                    String s = jsonObject.getString("amount") + jsonObject.get("payType") + jsonObject.get("serverNum") + jsonObject.get("transNumber") +
                            jsonObject.get("payStatus");
                    String md5Str = SecureUtil.md5(SecureUtil.md5(s) + byMerIdCache.getPrivateKey()).toLowerCase();

                    log.info("qmpay s " + s);
                    log.info("qmpay md5(s) " + md5Str);

                    if (md5Str.equals(sign)) {

                        if (order.getAmount().doubleValue() == jsonObject.getDouble("amount")) {

                            int b = platMerOrderService.success(order);

                            if (b > 0) {
                                report(order);
                                log.info("qmpay callback success");
                                return "success";
                            } else {
                                log.error("qmpay callback error");
                                return "error";
                            }

                        } else {
                            log.error("qmpay callback amount is error");
                            return "amount is error";
                        }

                    } else {
                        log.error("qmpay callback sign error");
                        return "sign error";
                    }

                } catch (RuntimeException ex) {
                    log.error("qmpay callback notify EpayException", ex);
                    return "error" + ex.getMessage();
                } catch (Exception ex) {
                    log.error("qmpay callback notify Exception", ex);
                    return "system ex ";
                } finally {
                    unlock(orderId);
                }

            } else {
                log.error("qmpay callback plat order id is empty" + orderId);
                return "plat order id is empty";
            }

        } else {
            log.error("qmpay callback plat order is error" + jsonObject.toJSONString());
            return "plat order status is error";
        }

    }


    public String jinshunfu(JSONObject jsonObject) {

        String merchOrder = jsonObject.getString("merOrderId");


        String sign = jsonObject.getString("sign");
        String status = jsonObject.getString("stat");
        //message
        jsonObject.remove("sign");
        SortedMap sortedMap = new TreeMap();
        for (String key : jsonObject.keySet()) {

            sortedMap.put(key, jsonObject.getString(key));
        }


        if (!"2".equals(status)) {
            return "status is error" + merchOrder;

        }
        if (StringUtils.isEmpty(merchOrder)) {

            log.error("plat order id is empty" + merchOrder);
            return "plat order id is empty";
        }

        try {
            if (!lock(merchOrder)) {
                return "error";
            }


            PlatMerOrder byOrderId = platMerOrderService.getByOrderId(merchOrder);

            if (StringUtils.equals(byOrderId.getStat(), "2")) {
                return "success";
            }

            PlatMer byMerIdCache = platMerService.getByMerIdCache(byOrderId.getMerId());

            if (byMerIdCache == null) {
                return "plat mer is empty not fund";
            }

            String s = convertUrl(sortedMap, "&", "=") + "&key=" + byMerIdCache.getPrivateKey();
//            String sign = SecureUtil.md5(s +"&"+ byMerIdCache.getPrivateKey()).toLowerCase();
            log.error(" sign url error {}", s);
            if (!SecureUtil.md5(s).toLowerCase().equals(sign)) {
                return "sign error";
            }


            if (byOrderId.getAmount().doubleValue() != jsonObject.getDouble("amount")) {
                return "amount is  error";
            }

            int b = platMerOrderService.success(byOrderId);
            if (b > 0) {


                report(byOrderId);

                return "success";
            }
            return "error";

        } catch (RuntimeException ex) {
            log.error("notify EpayException", ex);
            return "error" + ex.getMessage();
        } catch (Exception ex) {
            log.error("notify Exception", ex);
            return "system ex ";
        } finally {
            unlock(merchOrder);
        }
    }

    public String huaxinUrl(JSONObject jsonObject) {
        log.info("huaxin callback jsonObject " + jsonObject);
        String orderId = jsonObject.getString("mchOrderNo");
        String status = jsonObject.getString("status");
        String sign = jsonObject.getString("sign");
        log.info(String.format("huaxin callback orderId=%s, status=%s, sign=%s", orderId, status, sign));

        if ("2".equals(status)) {

            if (!StringUtils.isEmpty(orderId)) {

                try {

                    if (!lock(orderId)) {
                        log.error("huaxin callback is lock");
                        return "error";
                    }

                    PlatMerOrder order = platMerOrderService.getByOrderId(orderId);
                    if (StringUtils.equals(order.getStat(), "2")) {
                        log.info("huaxin callback order success");
                        return "success";
                    }

                    PlatMer byMerIdCache = platMerService.getByMerIdCache(order.getMerId());
                    if (byMerIdCache == null) {
                        log.info("huaxin callback plat mer is empty not fund");
                        return "plat mer is empty not fund";
                    }

                    jsonObject.remove("sign");
                    SortedMap sortedMap = new TreeMap();
                    for (String key : jsonObject.keySet()) {
                        sortedMap.put(key, jsonObject.getString(key));
                    }
                    String s = convertUrlNotEmpty(sortedMap, "&", "=") + "&key=" + byMerIdCache.getPrivateKey();
                    String md5Str = SecureUtil.md5(s).toUpperCase();

                    log.info("huaxin s " + s);
                    log.info("huaxin md5(s) " + md5Str);

                    if (md5Str.equals(sign)) {

                        if ((order.getAmount().multiply(new BigDecimal(100)).doubleValue() == jsonObject.getDouble("amount"))) {

                            int b = platMerOrderService.success(order);

                            if (b > 0) {
                                report(order);
                                log.info("success");
                                return "success";
                            } else {
                                log.error("huaxin callback error");
                                return "error";
                            }

                        } else {
                            log.error("huaxin callback amount is error orderAmount " + order.getAmount() + " jsonAmount " + jsonObject.get("amount"));
                            return "amount is error";
                        }

                    } else {
                        log.error("huaxin callback sign error");
                        return "sign error";
                    }

                } catch (RuntimeException ex) {
                    log.error("huaxin callback notify EpayException", ex);
                    return "error" + ex.getMessage();
                } catch (Exception ex) {
                    log.error("huaxin callback notify Exception", ex);
                    return "system ex ";
                } finally {
                    unlock(orderId);
                }

            } else {
                log.error("huaxin callback plat order id is empty" + orderId);
                return "plat order id is empty";
            }

        } else {
            log.error("huaxin callback plat order is error" + jsonObject.toJSONString());
            return "plat order status is error";
        }

    }

    public String jinshunfuUrl(JSONObject jsonObject) {
        log.info("jinshunfu callback jsonObject " + jsonObject);
        String orderId = jsonObject.getString("merOrderId");
        String status = jsonObject.getString("stat");
        String sign = jsonObject.getString("sign");
        log.info(String.format("jinshunfu callback orderId=%s, status=%s, sign=%s", orderId, status, sign));

        if ("2".equals(status)) {

            if (!StringUtils.isEmpty(orderId)) {

                try {

                    if (!lock(orderId)) {
                        log.error("jinshunfu callback is lock");
                        return "error";
                    }

                    PlatMerOrder order = platMerOrderService.getByOrderId(orderId);
                    if (StringUtils.equals(order.getStat(), "2")) {
                        log.info("jinshunfu callback order success");
                        return "success";
                    }

                    PlatMer byMerIdCache = platMerService.getByMerIdCache(order.getMerId());
                    if (byMerIdCache == null) {
                        log.info("jinshunfu callback plat mer is empty not fund");
                        return "plat mer is empty not fund";
                    }

                    jsonObject.remove("sign");
                    SortedMap sortedMap = new TreeMap();
                    for (String key : jsonObject.keySet()) {
                        sortedMap.put(key, jsonObject.getString(key));
                    }
                    String s = convertUrlNotEmpty(sortedMap, "&", "=") + "&key=" + byMerIdCache.getPrivateKey();
                    String md5Str = SecureUtil.md5(s).toLowerCase();

                    log.info("jinshunfu s " + s);
                    log.info("jinshunfu md5(s) " + md5Str);

                    if (md5Str.equals(sign)) {

                        if (order.getAmount().doubleValue() == jsonObject.getDouble("amount")) {

                            int b = platMerOrderService.success(order);

                            if (b > 0) {
                                report(order);
                                log.info("success");
                                return "jinshunfu callback success";
                            } else {
                                log.error("jinshunfu callback error");
                                return "error";
                            }

                        } else {
                            log.error("jinshunfu callback amount is error orderAmount " + order.getAmount() + " jsonAmount " + jsonObject.get("amount"));
                            return "amount is error";
                        }

                    } else {
                        log.error("jinshunfu callback sign error");
                        return "sign error";
                    }

                } catch (RuntimeException ex) {
                    log.error("jinshunfu callback notify EpayException", ex);
                    return "error" + ex.getMessage();
                } catch (Exception ex) {
                    log.error("jinshunfu callback notify Exception", ex);
                    return "system ex ";
                } finally {
                    unlock(orderId);
                }

            } else {
                log.error("jinshunfu callback plat order id is empty" + orderId);
                return "plat order id is empty";
            }

        } else {
            log.error("jinshunfu callback plat order is error" + jsonObject.toJSONString());
            return "plat order status is error";
        }

    }

    public String juzi(JSONObject jsonObject) {

        String merchOrder = jsonObject.getString("customno");

        String sign = jsonObject.getString("sign");
        String status = jsonObject.getString("state");
        //message
        jsonObject.remove("sign");
        Map<String, Object> sortedMap = new LinkedHashMap<>();
        sortedMap.put("merchant", jsonObject.get("merchant").toString());
        sortedMap.put("merchant_money", jsonObject.get("merchant_money").toString());
        sortedMap.put("qrtype", jsonObject.get("qrtype").toString());
        sortedMap.put("customno", jsonObject.get("customno").toString());
        sortedMap.put("sendtime", jsonObject.get("sendtime").toString());
        sortedMap.put("orderno", jsonObject.get("orderno").toString());
        sortedMap.put("money", jsonObject.get("money").toString());
        sortedMap.put("paytime", jsonObject.get("paytime").toString());
        sortedMap.put("state", jsonObject.get("state").toString());

        if (!"1".equals(status)) {
            return "status is error" + merchOrder;

        }
        if (StringUtils.isEmpty(merchOrder)) {

            log.error("plat order id is empty" + merchOrder);
            return "plat order id is empty";
        }

        try {
            if (!lock(merchOrder)) {
                return "error";
            }


            PlatMerOrder byOrderId = platMerOrderService.getByOrderId(merchOrder);

            if (StringUtils.equals(byOrderId.getStat(), "2")) {
                return "OK";
            }

            PlatMer byMerIdCache = platMerService.getByMerIdCache(byOrderId.getMerId());

            if (byMerIdCache == null) {
                return "plat mer is empty not fund";
            }

            String s = convertUrlNotEmpty(sortedMap, "&", "=") + byMerIdCache.getPrivateKey();
//            String sign = SecureUtil.md5(s +"&"+ byMerIdCache.getPrivateKey()).toLowerCase();
            log.error(" sign url error {}", s);
            if (!SecureUtil.md5(s).toLowerCase().equals(sign)) {
                return "sign error";
            }


            if (byOrderId.getAmount().doubleValue() != jsonObject.getDouble("money")) {
                return "amount is  error";
            }

            int b = platMerOrderService.success(byOrderId);
            if (b > 0) {
                report(byOrderId);
                log.info("ok");
                return "OK";
            }
            return "error";

        } catch (RuntimeException ex) {
            log.error("notify EpayException", ex);
            return "error" + ex.getMessage();
        } catch (Exception ex) {
            log.error("notify Exception", ex);
            return "system ex ";
        } finally {
            unlock(merchOrder);
        }
    }

    public String xinfubaoPay(JSONObject jsonObject) {

        String merchOrder = jsonObject.getString("orderid");

        String status = jsonObject.getString("code");
        String sign = jsonObject.getString("sign");

        //message
        jsonObject.remove("sign");
        jsonObject.remove("attach");

        if (!status.equals("00")) {
            log.error("plat order is error" + jsonObject.toJSONString());
            return "plat order status is error";
        }
        SortedMap sortedMap = new TreeMap();
        for (String key : jsonObject.keySet()) {

            sortedMap.put(key, jsonObject.getString(key));
        }

        if (StringUtils.isEmpty(merchOrder)) {

            log.error("plat order id is empty" + merchOrder);
            return "plat order id is empty";
        }

        try {
            if (!lock(merchOrder)) {
                return "error";
            }


            PlatMerOrder byOrderId = platMerOrderService.getByOrderId(merchOrder);

            if (StringUtils.equals(byOrderId.getStat(), "2")) {
                return "SUCCESS";
            }

            PlatMer byMerIdCache = platMerService.getByMerIdCache(byOrderId.getMerId());

            if (byMerIdCache == null) {
                return "plat mer is empty not fund";
            }

            String s = convertUrlNotEmpty(sortedMap, "&", "=") + "&key=" + byMerIdCache.getPrivateKey();
            log.error(" sign url error {}", s);
//            String sign = SecureUtil.md5(s +"&"+ byMerIdCache.getPrivateKey()).toLowerCase();
            log.error(" sign url error {}", s);
            if (!SecureUtil.md5(s).toUpperCase().equals(sign)) {
                return "sign error";
            }


            if (byOrderId.getAmount().doubleValue() != jsonObject.getDouble("price")) {
                return "amount is  error";
            }

            int b = platMerOrderService.success(byOrderId);
            if (b > 0) {


                report(byOrderId);

                return "SUCCESS";
            }
            return "error";

        } catch (RuntimeException ex) {
            log.error("notify EpayException", ex);
            return "error" + ex.getMessage();
        } catch (Exception ex) {
            log.error("notify Exception", ex);
            return "system ex ";
        } finally {
            unlock(merchOrder);
        }

    }


    public String caiyingNew(JSONObject jsonObject) {

        String merchOrder = jsonObject.getString("orderNo");

        String status = jsonObject.getString("state");
        String sign = jsonObject.getString("sign");

        //message
        jsonObject.remove("sign");

        if (!status.equals("1")) {
            log.error("plat order is error" + jsonObject.toJSONString());
            return "plat order status is error";
        }


        if (StringUtils.isEmpty(merchOrder)) {

            log.error("plat order id is empty" + merchOrder);
            return "plat order id is empty";
        }

        try {
            if (!lock(merchOrder)) {
                return "error";
            }


            PlatMerOrder byOrderId = platMerOrderService.getByOrderId(merchOrder);

            if (StringUtils.equals(byOrderId.getStat(), "2")) {
                return "SUCCESS";
            }

            PlatMer byMerIdCache = platMerService.getByMerIdCache(byOrderId.getMerId());

            if (byMerIdCache == null) {
                return "plat mer is empty not fund";
            }

            String s = jsonObject.getString("state") + byMerIdCache.getMerKey() + jsonObject.getString("orderNo") + jsonObject.getString("amount") + byMerIdCache.getPrivateKey();
            log.error(" sign url error {}", s);
//            String sign = SecureUtil.md5(s +"&"+ byMerIdCache.getPrivateKey()).toLowerCase();
            log.error(" sign url error {}", s);
            if (!SecureUtil.md5(s).toLowerCase().equals(sign)) {
                return "sign error";
            }


            if (byOrderId.getAmount().doubleValue() != jsonObject.getDouble("amount")) {
                return "amount is  error";
            }

            int b = platMerOrderService.success(byOrderId);
            if (b > 0) {


                report(byOrderId);

                return "SUCCESS";
            }
            return "error";

        } catch (RuntimeException ex) {
            log.error("notify EpayException", ex);
            return "error" + ex.getMessage();
        } catch (Exception ex) {
            log.error("notify Exception", ex);
            return "system ex ";
        } finally {
            unlock(merchOrder);
        }

    }

    public String yhpayCall(JSONObject jsonObject) {

        return yinFuTong(jsonObject);
    }

    public String wenxinpay(JSONObject jsonObject) {

        return yinFuTong(jsonObject);
    }

    public String ukafu(JSONObject jsonObject) {

        return yinFuTong(jsonObject);
    }

    public String meiruibaoUrl(JSONObject jsonObject) {
        log.info("meiruibao callback jsonObject " + jsonObject);
        String orderId = jsonObject.getString("customer_order_no");
        String status = jsonObject.getString("status");
        String sign = jsonObject.getString("sign");
        log.info(String.format("meiruibao callback orderId=%s, status=%s, sign=%s", orderId, status, sign));

        if ("1".equals(status)) {

            if (!StringUtils.isEmpty(orderId)) {

                try {

                    if (!lock(orderId)) {
                        log.error("meiruibao callback is lock");
                        return "error";
                    }

                    PlatMerOrder order = platMerOrderService.getByOrderId(orderId);
                    if (StringUtils.equals(order.getStat(), "2")) {
                        log.info("meiruibao callback order success");
                        return "success";
                    }

                    PlatMer byMerIdCache = platMerService.getByMerIdCache(order.getMerId());
                    if (byMerIdCache == null) {
                        log.info("meiruibao callback plat mer is empty not fund");
                        return "plat mer is empty not fund";
                    }

                    jsonObject.remove("sign");
                    Map<String, String> sortedMap = new TreeMap();
                    for (String key : jsonObject.keySet()) {
                        sortedMap.put(key, jsonObject.getString(key));
                    }
                    String s = convertUrlIsEmpty(sortedMap, "&", "=") + "&key=" + byMerIdCache.getPrivateKey();
                    String md5Str = SecureUtil.md5(s).toLowerCase();

                    log.info("meiruibao s " + s);
                    log.info("meiruibao md5(s) " + md5Str);

                    if (md5Str.equals(sign)) {

                        if (order.getAmount().doubleValue() == jsonObject.getDouble("money")) {

                            int b = platMerOrderService.success(order);

                            if (b > 0) {
                                report(order);
                                log.info("success");
                                return "meiruibao callback success";
                            } else {
                                log.error("meiruibao callback error");
                                return "error";
                            }

                        } else {
                            log.error("meiruibao callback amount is error orderAmount " + order.getAmount() + " jsonAmount " + jsonObject.get("amount"));
                            return "amount is error";
                        }

                    } else {
                        log.error("meiruibao callback sign error");
                        return "sign error";
                    }

                } catch (RuntimeException ex) {
                    log.error("meiruibao callback notify EpayException", ex);
                    return "error" + ex.getMessage();
                } catch (Exception ex) {
                    log.error("meiruibao callback notify Exception", ex);
                    return "system ex ";
                } finally {
                    unlock(orderId);
                }

            } else {
                log.error("meiruibao callback plat order id is empty" + orderId);
                return "plat order id is empty";
            }

        } else {
            log.error("meiruibao callback plat order is error" + jsonObject.toJSONString());
            return "plat order status is error";
        }

    }

    public String hnpay(JSONObject jsonObject) {
        log.info("hnpay callback jsonObject " + jsonObject);
        String orderId = jsonObject.getString("orderid");
        String status = jsonObject.getString("opstate");
        String sign = jsonObject.getString("sign");
        log.info(String.format("meiruibao callback orderId=%s, status=%s, sign=%s", orderId, status, sign));

        if ("0".equals(status)) {

            if (!StringUtils.isEmpty(orderId)) {

                try {

                    if (!lock(orderId)) {
                        log.error("meiruibao callback is lock");
                        return "error";
                    }

                    PlatMerOrder order = platMerOrderService.getByOrderId(orderId);
                    if (StringUtils.equals(order.getStat(), "2")) {
                        log.info("meiruibao callback order success");
                        return "opstate=0";
                    }

                    PlatMer byMerIdCache = platMerService.getByMerIdCache(order.getMerId());
                    if (byMerIdCache == null) {
                        log.info("meiruibao callback plat mer is empty not fund");
                        return "plat mer is empty not fund";
                    }

                    jsonObject.remove("sign");

                    String s = "orderid=" + jsonObject.getString("orderid") + "&opstate=" + jsonObject.getString("opstate") + "&ovalue=" + jsonObject.getString("ovalue") + byMerIdCache.getPrivateKey();
                    String md5Str = SecureUtil.md5(s).toLowerCase();

                    log.info("meiruibao s " + s);
                    log.info("meiruibao md5(s) " + md5Str);

                    if (md5Str.equals(sign)) {

                        if (order.getAmount().doubleValue() == jsonObject.getDouble("ovalue")) {

                            int b = platMerOrderService.success(order);

                            if (b > 0) {
                                report(order);
                                log.info("success");
                                return "opstate=0";
                            } else {
                                log.error("meiruibao callback error");
                                return "error";
                            }

                        } else {
                            log.error("meiruibao callback amount is error orderAmount " + order.getAmount() + " jsonAmount " + jsonObject.get("amount"));
                            return "amount is error";
                        }

                    } else {
                        log.error("meiruibao callback sign error");
                        return "sign error";
                    }

                } catch (RuntimeException ex) {
                    log.error("meiruibao callback notify EpayException", ex);
                    return "error" + ex.getMessage();
                } catch (Exception ex) {
                    log.error("meiruibao callback notify Exception", ex);
                    return "system ex ";
                } finally {
                    unlock(orderId);
                }

            } else {
                log.error("meiruibao callback plat order id is empty" + orderId);
                return "plat order id is empty";
            }

        } else {
            log.error("meiruibao callback plat order is error" + jsonObject.toJSONString());
            return "plat order status is error";
        }

    }

    public String wykktUrl(JSONObject jsonObject) {
        log.info("wykkt callback jsonObject " + jsonObject);
        String orderId = jsonObject.getString("orderRemark");
        String status = jsonObject.getString("state");
        String sign = jsonObject.getString("hmac");
        log.info(String.format("wykkt callback orderId=%s, status=%s, sign=%s", orderId, status, sign));

        if ("3".equals(status)) {

            if (!StringUtils.isEmpty(orderId)) {

                try {

                    if (!lock(orderId)) {
                        log.error("wykkt callback is lock");
                        return "error";
                    }

                    PlatMerOrder order = platMerOrderService.getByOrderId(orderId);
                    if (StringUtils.equals(order.getStat(), "2")) {
                        log.info("wykkt callback order success");
                        return "success";
                    }

                    PlatMer byMerIdCache = platMerService.getByMerIdCache(order.getMerId());
                    if (byMerIdCache == null) {
                        log.info("wykkt callback plat mer is empty not fund");
                        return "plat mer is empty not fund";
                    }

                    StringBuilder s = new StringBuilder("");
                    s.append(jsonObject.get("id")).append(byMerIdCache.getPrivateKey()).append(jsonObject.getString("orderRemark")).append(jsonObject.getString("state"))
                            .append(jsonObject.getString("type")).append(jsonObject.getString("updateTime")).append(jsonObject.getString("userId"));

                    String md5Str = SecureUtil.md5(s.toString()).toUpperCase();

                    log.info("wykkt s " + s);
                    log.info("wykkt md5(s) " + md5Str);

                    if (md5Str.equals(sign)) {

                        int b = platMerOrderService.success(order);

                        if (b > 0) {
                            report(order);
                            log.info("wykkt success");
                            return "success";
                        } else {
                            log.error("wykkt callback error");
                            return "error";
                        }

                    } else {
                        log.error("wykkt callback sign error");
                        return "sign error";
                    }

                } catch (RuntimeException ex) {
                    log.error("wykkt callback notify EpayException", ex);
                    return "error" + ex.getMessage();
                } catch (Exception ex) {
                    log.error("wykkt callback notify Exception", ex);
                    return "system ex ";
                } finally {
                    unlock(orderId);
                }

            } else {
                log.error("wykkt callback plat order id is empty" + orderId);
                return "plat order id is empty";
            }

        } else {
            log.error("wykkt callback plat order is error" + jsonObject.toJSONString());
            return "plat order status is error";
        }
    }

    public String fcpayUrl(JSONObject jsonObject) {
        log.info("fcpay callback jsonObject " + jsonObject);
        String orderId = jsonObject.getString("pay_orderid");
        String status = jsonObject.getString("status");
        String sign = jsonObject.getString("sign");
        log.info(String.format("fcpay callback orderId=%s, status=%s, sign=%s", orderId, status, sign));

//        if ("1".equals(status)) {

        if (!StringUtils.isEmpty(orderId)) {

            try {

                if (!lock(orderId)) {
                    log.error("fcpay callback is lock");
                    return "error";
                }

                PlatMerOrder order = platMerOrderService.getByOrderId(orderId);
                if (StringUtils.equals(order.getStat(), "2")) {
                    log.info("fcpay callback order success");
                    return "success";
                }

                PlatMer byMerIdCache = platMerService.getByMerIdCache(order.getMerId());
                if (byMerIdCache == null) {
                    log.info("fcpay callback plat mer is empty not fund");
                    return "plat mer is empty not fund";
                }

                jsonObject.remove("sign");
                Map<String, String> sortedMap = new TreeMap();
                for (String key : jsonObject.keySet()) {
                    sortedMap.put(key, jsonObject.getString(key));
                }
                String s = convertUrlIsEmpty(sortedMap, "&", "=") + "&key=" + byMerIdCache.getPrivateKey();

                String md5Str = SecureUtil.md5(s).toUpperCase();

                log.info("fcpay s " + s);
                log.info("fcpay md5(s) " + md5Str);

                if (md5Str.equals(sign)) {

                    if (order.getAmount().doubleValue() == (jsonObject.getDouble("price") / 100)) {

                        int b = platMerOrderService.success(order);

                        if (b > 0) {
                            report(order);
                            log.info("success");
                            return "success";
                        } else {
                            log.error("fcpay callback error");
                            return "error";
                        }

                    } else {
                        log.error("fcpay callback amount is error orderAmount " + order.getAmount() + " jsonAmount " + jsonObject.get("price"));
                        return "amount is error";
                    }

                } else {
                    log.error("fcpay callback sign error");
                    return "sign error";
                }

            } catch (RuntimeException ex) {
                log.error("fcpay callback notify EpayException", ex);
                return "error" + ex.getMessage();
            } catch (Exception ex) {
                log.error("fcpay callback notify Exception", ex);
                return "system ex ";
            } finally {
                unlock(orderId);
            }

        } else {
            log.error("fcpay callback plat order id is empty" + orderId);
            return "plat order id is empty";
        }

//        } else {
//            log.error("fcpay callback plat order is error" + jsonObject.toJSONString());
//            return "plat order status is error";
//        }

    }

    public String jiexunPay(JSONObject param) {

        return yinFuTong(param);
    }

    public String huitiao(JSONObject param) {

        return yinFuTong(param);
    }

    public String theUrl(JSONObject jsonObject) {
        log.info("theUrl callback jsonObject " + jsonObject);
        String orderId = jsonObject.getString("trade_no");
        String status = jsonObject.getString("status");
        String sign = jsonObject.getString("sign");
        log.info(String.format("theUrl callback orderId=%s, status=%s, sign=%s", orderId, status, sign));

//        if ("1".equals(status)) {

        if (!StringUtils.isEmpty(orderId)) {

            try {

                if (!lock(orderId)) {
                    log.error("theUrl callback is lock");
                    return "error";
                }

                PlatMerOrder order = platMerOrderService.getByOrderId(orderId);
                if (StringUtils.equals(order.getStat(), "2")) {
                    log.info("theUrl callback order success");
                    return "success";
                }

                PlatMer byMerIdCache = platMerService.getByMerIdCache(order.getMerId());
                if (byMerIdCache == null) {
                    log.info("theUrl callback plat mer is empty not fund");
                    return "plat mer is empty not fund";
                }

                String s = "trade_no=" + jsonObject.getString("trade_no") + "&pay_type=" + jsonObject.getString("pay_type") +
                        "&pay_amount=" + jsonObject.getString("pay_amount") + "&receipt_amount=" + jsonObject.getString("receipt_amount") +
                        "&paydate=" + jsonObject.getString("paydate") + byMerIdCache.getPrivateKey();
                String md5Str = SecureUtil.md5(s);

                log.info("theUrl s " + s);
                log.info("theUrl md5(s) " + md5Str);

                if (md5Str.equals(sign)) {

                    if (order.getAmount().doubleValue() == jsonObject.getDouble("pay_amount")) {

                        int b = platMerOrderService.success(order);

                        if (b > 0) {
                            report(order);
                            log.info("success");
                            return "success";
                        } else {
                            log.error("theUrl callback error");
                            return "error";
                        }

                    } else {
                        log.error("theUrl callback amount is error orderAmount " + order.getAmount() + " jsonAmount " + jsonObject.get("amount"));
                        return "theUrl is error";
                    }

                } else {
                    log.error("theUrl callback sign error");
                    return "sign error";
                }

            } catch (RuntimeException ex) {
                log.error("theUrl callback notify EpayException", ex);
                return "error" + ex.getMessage();
            } catch (Exception ex) {
                log.error("theUrl callback notify Exception", ex);
                return "system ex ";
            } finally {
                unlock(orderId);
            }

        } else {
            log.error("theUrl callback plat order id is empty" + orderId);
            return "plat order id is empty";
        }

    }
//        else {
//            log.error("theUrl callback plat order is error" + jsonObject.toJSONString());
//            return "plat order status is error";
//        }
//    }

    public String sjpayUrl(JSONObject jsonObject) {
        log.info("sjpayUrl jsonObject " + jsonObject);
        String orderId = jsonObject.getString("out_trade_no");
        String status = jsonObject.getString("callbacks");
        String sign = jsonObject.getString("sign");
        log.info(String.format("orderId=%s, status=%s, sign=%s", orderId, status, sign));

        if ("CODE_SUCCESS".equals(status)) {

            if (!StringUtils.isEmpty(orderId)) {

                try {

                    if (!lock(orderId)) {
                        log.error("sjpayUrl is lock");
                        return "error";
                    }

                    PlatMerOrder order = platMerOrderService.getByOrderId(orderId);
                    if (StringUtils.equals(order.getStat(), "2")) {
                        return "success";
                    }

                    PlatMer byMerIdCache = platMerService.getByMerIdCache(order.getMerId());
                    if (byMerIdCache == null) {
                        return "plat mer is empty not fund";
                    }

                    jsonObject.remove("sign");
                    Map<String, String> map = new TreeMap<>();
                    for (String key : jsonObject.keySet()) {
                        if (null != jsonObject.get(key) && !"".equals(jsonObject.get(key))) {
                            map.put(key, jsonObject.get(key).toString());
                        }
                    }
                    String s = convertUrl(map, "&", "=") + "&key=" + byMerIdCache.getPrivateKey();
                    String md5Str = SecureUtil.md5(s);
                    log.info("s " + s);
                    log.info("md5(s) " + md5Str);

                    if (md5Str.toUpperCase().equals(sign)) {

                        if (order.getAmount().doubleValue() == jsonObject.getDouble("amount")) {

                            int b = platMerOrderService.success(order);

                            if (b > 0) {
                                report(order);
                                log.info("ok");
                                return "success";
                            } else {
                                log.error("error");
                                return "error";
                            }

                        } else {
                            log.error("amount is error");
                            return "amount is error";
                        }

                    } else {
                        log.error("sign error");
                        return "sign error";
                    }

                } catch (RuntimeException ex) {
                    log.error("notify EpayException", ex);
                    return "error" + ex.getMessage();
                } catch (Exception ex) {
                    log.error("notify Exception", ex);
                    return "system ex ";
                } finally {
                    unlock(orderId);
                }

            } else {
                log.error("plat order id is empty" + orderId);
                return "plat order id is empty";
            }

        } else {
            log.error("plat order is error" + jsonObject.toJSONString());
            return "plat order status is error";
        }

    }

    public static String AES_cbc_decrypt(String encData, String password, String iv) throws Exception {
        byte[] key = new byte[32];
        for (int i = 0; i < 32; i++) {
            if (i < password.getBytes().length) {
                key[i] = password.getBytes()[i];
            } else {
                key[i] = 0;
            }
        }
        Cipher cipher = Cipher.getInstance(ALGORITHM);
        cipher.init(Cipher.DECRYPT_MODE, new SecretKeySpec(key, "AES"), new IvParameterSpec(iv.getBytes()));
        return new String(cipher.doFinal(Base64.getDecoder().decode(encData)));
    }

    public String andaUrl(JSONObject jsonObject) throws Exception {
        log.info("anda jsonObject " + jsonObject);
        String content = jsonObject.getString("content");


        jsonObject = JSONObject.parseObject(AES_cbc_decrypt(content, "RWYRzciqol89OPn3fOtJw3nmnOygjoZc", "2gg9SAHYGg5bhcrr"));
        String orderId = jsonObject.getString("order_no");
        String status = jsonObject.getString("status");
        String sign = jsonObject.getString("sign");
        log.info(String.format("anda=%s, status=%s, sign=%s", orderId, status, sign));

        if ("succeed".equals(status)) {

            if (!StringUtils.isEmpty(orderId)) {

                try {

                    if (!lock(orderId)) {
                        log.error("anda is lock");
                        return "error";
                    }

                    PlatMerOrder order = platMerOrderService.getByOrderId(orderId);
                    if (StringUtils.equals(order.getStat(), "2")) {
                        return "success";
                    }

                    PlatMer byMerIdCache = platMerService.getByMerIdCache(order.getMerId());
                    if (byMerIdCache == null) {
                        return "plat mer is empty not fund";
                    }

                    jsonObject.remove("sign");
                    Map<String, String> map = new TreeMap<>();
                    for (String key : jsonObject.keySet()) {
                        map.put(key, jsonObject.get(key).toString());
                    }
                    String s = convertUrl(map, "&", "=") + "&key=" + byMerIdCache.getPrivateKey();
                    String md5Str = SecureUtil.md5(s);
                    log.info("s " + s);
                    log.info("md5(s) " + md5Str);

//                    if (md5Str.toUpperCase().equals(sign)) {

                    if (order.getAmount().doubleValue() == jsonObject.getDouble("actual_amount")) {

                        int b = platMerOrderService.success(order);

                        if (b > 0) {
                            report(order);
                            log.info("ok");
                            return "success";
                        } else {
                            log.error("error");
                            return "error";
                        }

                    } else {
                        log.error("amount is error");
                        return "amount is error";
                    }


                } catch (RuntimeException ex) {
                    log.error("notify EpayException", ex);
                    return "error" + ex.getMessage();
                } catch (Exception ex) {
                    log.error("notify Exception", ex);
                    return "system ex ";
                } finally {
                    unlock(orderId);
                }

            } else {
                log.error("plat order id is empty" + orderId);
                return "plat order id is empty";
            }

        } else {
            log.error("plat order is error" + jsonObject.toJSONString());
            return "plat order status is error";
        }

    }

    public String shangshangkejiPay(JSONObject jsonObject) {

        return pilinUrl(jsonObject);
    }

    public String dongyayifaPay(JSONObject jsonObject) {
        return pilinUrl(jsonObject);
    }

    public String kaijiaUrl(JSONObject jsonObject) {
        log.info("kaijia jsonObject " + jsonObject);
        String orderId = jsonObject.getString("customOrderId");
        String status = jsonObject.getString("status");
        String sign = jsonObject.getString("sign");
        log.info(String.format("kaijia =%s, status=%s, sign=%s", orderId, status, sign));

        if ("1".equals(status)) {

            if (!StringUtils.isEmpty(orderId)) {

                try {

                    if (!lock(orderId)) {
                        log.error("kaijia is lock");
                        return "error";
                    }

                    PlatMerOrder order = platMerOrderService.getByOrderId(orderId);
                    if (StringUtils.equals(order.getStat(), "2")) {
                        return "success";
                    }

                    PlatMer byMerIdCache = platMerService.getByMerIdCache(order.getMerId());
                    if (byMerIdCache == null) {
                        return "plat mer is empty not fund";
                    }

                    String s = byMerIdCache.getMerKey() + jsonObject.getString("status") + jsonObject.getString("customOrderId") +
                            jsonObject.getString("amount") + jsonObject.getString("realAmount") + jsonObject.getString("payTime")
                            + jsonObject.getString("remark") + byMerIdCache.getPrivateKey();
                    String md5Str = SecureUtil.md5(s);
                    log.info("kaijia s" + s);
                    log.info("kaijia md5(s) " + md5Str);

                    if (md5Str.equals(sign)) {

                        if ((order.getAmount().doubleValue() * 100) == jsonObject.getDouble("realAmount")) {

                            int b = platMerOrderService.success(order);

                            if (b > 0) {
                                report(order);
                                log.info("kaijia ok");
                                return "SUCCESS";
                            } else {
                                log.error("error");
                                return "error";
                            }

                        } else {
                            log.error("kaijia amount is error");
                            return "amount is error";
                        }

                    } else {
                        log.error("kaijia sign error");
                        return "sign error";
                    }

                } catch (RuntimeException ex) {
                    log.error("kaijia notify EpayException", ex);
                    return "error" + ex.getMessage();
                } catch (Exception ex) {
                    log.error("kaijia notify Exception", ex);
                    return "system ex ";
                } finally {
                    unlock(orderId);
                }

            } else {
                log.error("kaijia plat order id is empty" + orderId);
                return "plat order id is empty";
            }

        } else {
            log.error("kaijia plat order is error" + jsonObject.toJSONString());
            return "plat order status is error";
        }

    }

    public String chuanyepay(JSONObject jsonObject) {
        return jinxinUrl(jsonObject);
    }

    public String hskjpay(JSONObject jsonObject) {
        return jinxinUrl(jsonObject);
    }

    public String sfkj(JSONObject jsonObject) {
        return jinxinUrl(jsonObject);
    }

    public String XGPay(JSONObject jsonObject) {
        log.info("XG callback jsonObject " + jsonObject);
        String orderId = jsonObject.getString("fxddh");
        String status = jsonObject.getString("fxstatus");
        String sign = jsonObject.getString("fxsign");
        log.info(String.format("XG callback =%s, status=%s, sign=%s", orderId, status, sign));

        if ("1".equals(status)) {

            if (!StringUtils.isEmpty(orderId)) {

                try {

                    if (!lock(orderId)) {
                        log.error("XG callback is lock");
                        return "error";
                    }

                    PlatMerOrder order = platMerOrderService.getByOrderId(orderId);
                    if (StringUtils.equals(order.getStat(), "2")) {
                        return "success";
                    }

                    PlatMer byMerIdCache = platMerService.getByMerIdCache(order.getMerId());
                    if (byMerIdCache == null) {
                        return "plat mer is empty not fund";
                    }

                    String s = jsonObject.getString("fxstatus") + jsonObject.getString("fxid") + jsonObject.getString("fxddh") +
                            jsonObject.getString("fxfee") + byMerIdCache.getPrivateKey();
                    String md5Str = SecureUtil.md5(s);
                    log.info("XG callback s" + s);
                    log.info("XG callback md5(s) " + md5Str);

                    if (md5Str.equals(sign)) {

                        if ((order.getAmount().doubleValue()) == jsonObject.getDouble("fxfee")) {

                            int b = platMerOrderService.success(order);

                            if (b > 0) {
                                report(order);
                                log.info("success");
                                return "success";
                            } else {
                                log.error("error");
                                return "error";
                            }

                        } else {
                            log.error("XG callback amount is error");
                            return "amount is error";
                        }

                    } else {
                        log.error("XG callback sign error");
                        return "sign error";
                    }

                } catch (RuntimeException ex) {
                    log.error("XG callback notify EpayException", ex);
                    return "error" + ex.getMessage();
                } catch (Exception ex) {
                    log.error("XG callback notify Exception", ex);
                    return "system ex ";
                } finally {
                    unlock(orderId);
                }

            } else {
                log.error("XG callback plat order id is empty" + orderId);
                return "plat order id is empty";
            }

        } else {
            log.error("XG callback plat order is error" + jsonObject.toJSONString());
            return "plat order status is error";
        }

    }

    public String huote(JSONObject jsonObject) {
        return caiyingUrl(jsonObject);
    }

    public String xiaocaoPay(JSONObject jsonObject) {

//        AES_cbc_decrypt(jsonObject.getString("content"), );

        log.info("xiaocao callback jsonObject " + jsonObject);
        String orderId = jsonObject.getString("orderId");
//        String status = jsonObject.getString("fxstatus");
        String sign = jsonObject.getString("sign");
        log.info(String.format("xiaocao callback orderId=%s, sign=%s", orderId, sign));

//        if ("1".equals(status)) {

        if (!StringUtils.isEmpty(orderId)) {

            try {

                if (!lock(orderId)) {
                    log.error("xiaocao callback is lock");
                    return "error";
                }

                PlatMerOrder order = platMerOrderService.getByOrderId(orderId);
                if (StringUtils.equals(order.getStat(), "2")) {
                    return "success";
                }

                PlatMer byMerIdCache = platMerService.getByMerIdCache(order.getMerId());
                if (byMerIdCache == null) {
                    return "plat mer is empty not fund";
                }

                jsonObject.remove("sign");
                Map<String, Object> map = new TreeMap<>();
                for (String key : jsonObject.keySet()) {
                    map.put(key, jsonObject.get(key).toString());
                }
                String s = convertUrlNotEmpty(map, "&", "=") + "&key=" + byMerIdCache.getPrivateKey();
                String md5Str = SecureUtil.md5(s);
                log.info("xiaocao callback s" + s);
                log.info("xiaocao callback md5(s) " + md5Str);

                if (md5Str.equals(sign)) {

                    if ((order.getAmount().doubleValue()) == jsonObject.getDouble("money").doubleValue()) {

                        int b = platMerOrderService.success(order);

                        if (b > 0) {
                            report(order);
                            log.info("SUCCESS");
                            return "SUCCESS";
                        } else {
                            log.error("error");
                            return "error";
                        }

                    } else {
                        log.error("xiaocao callback amount is error");
                        return "amount is error";
                    }

                } else {
                    log.error("xiaocao callback sign error");
                    return "sign error";
                }

            } catch (RuntimeException ex) {
                log.error("xiaocao callback notify EpayException", ex);
                return "error" + ex.getMessage();
            } catch (Exception ex) {
                log.error("xiaocao callback notify Exception", ex);
                return "system ex ";
            } finally {
                unlock(orderId);
            }

        } else {
            log.error("xiaocao callback plat order id is empty" + orderId);
            return "plat order id is empty";
        }

//        } else {
//            log.error("xiaocao callback plat order is error" + jsonObject.toJSONString());
//            return "plat order status is error";
//        }

    }

    public String jiebaoPay(JSONObject jsonObject) {
        log.info("jiebao callback jsonObject " + jsonObject);
        String orderId = jsonObject.getString("MerOrderNo");
        String status = jsonObject.getString("PayStatus");
        String sign = jsonObject.getString("Sign");
        log.info("jiebao callback orderId={}, status={} sign={}", orderId, status, sign);

        if ("success".equals(status)) {

            if (!StringUtils.isEmpty(orderId)) {

                try {

                    if (!lock(orderId)) {
                        log.error("jiebao callback is lock");
                        return "error";
                    }

                    PlatMerOrder order = platMerOrderService.getByOrderId(orderId);
                    if (StringUtils.equals(order.getStat(), "2")) {
                        return "success";
                    }

                    PlatMer byMerIdCache = platMerService.getByMerIdCache(order.getMerId());
                    if (byMerIdCache == null) {
                        return "plat mer is empty not fund";
                    }

                    jsonObject.remove("Sign");
                    Map<String, Object> map = new TreeMap<>();
                    for (String key : jsonObject.keySet()) {
                        map.put(key, jsonObject.get(key).toString());
                    }
                    String s = convertUrlNotEmpty(map, "&", "=") + "&key=" + byMerIdCache.getPrivateKey();
                    String md5Str = SecureUtil.md5(s).toUpperCase();
                    log.info("jiebao callback s" + s);
                    log.info("jiebao callback md5(s) " + md5Str);

                    if (md5Str.equals(sign)) {
                        double min = order.getAmount().subtract(new BigDecimal(1)).multiply(new BigDecimal(100)).doubleValue();
                        double max = order.getAmount().add(new BigDecimal(1)).multiply(new BigDecimal(100)).doubleValue();

                        Double pay_money = jsonObject.getDouble("AmountReal");
                        /**
                         * 浮动金额
                         */
                        if ((pay_money.doubleValue() >= min && pay_money.doubleValue() <= max)) {

                            int b = platMerOrderService.success(order);

                            if (b > 0) {
                                report(order);
                                log.info("success");
                                return "success";
                            } else {
                                log.error("error");
                                return "error";
                            }

                        } else {
                            log.error("jiebao callback amount is error amount {}", order.getAmount());
                            return "amount is error";
                        }

                    } else {
                        log.error("jiebao callback sign error");
                        return "sign error";
                    }

                } catch (RuntimeException ex) {
                    log.error("jiebao callback notify EpayException", ex);
                    return "error" + ex.getMessage();
                } catch (Exception ex) {
                    log.error("jiebao callback notify Exception", ex);
                    return "system ex ";
                } finally {
                    unlock(orderId);
                }

            } else {
                log.error("jiebao callback plat order id is empty" + orderId);
                return "plat order id is empty";
            }

        } else {
            log.error("jiebao callback plat order is error" + jsonObject.toJSONString());
            return "plat order status is error";
        }

    }

    public String sixsixPay(JSONObject jsonObject) {
        log.info("sixsix callback jsonObject " + jsonObject);
        String orderId = jsonObject.getString("customOrderId");
        String status = jsonObject.getString("status");
        String sign = jsonObject.getString("sign");
        log.info("sixsix callback orderId={}, status={} sign={}", orderId, status, sign);

        if ("success".equals(status)) {

            if (!StringUtils.isEmpty(orderId)) {

                try {

                    if (!lock(orderId)) {
                        log.error("sixsix callback is lock");
                        return "error";
                    }

                    PlatMerOrder order = platMerOrderService.getByOrderId(orderId);
                    if (StringUtils.equals(order.getStat(), "2")) {
                        return "success";
                    }

                    PlatMer byMerIdCache = platMerService.getByMerIdCache(order.getMerId());
                    if (byMerIdCache == null) {
                        return "plat mer is empty not fund";
                    }

                    String s = jsonObject.getString("appid") + jsonObject.getString("status") + jsonObject.getString("customOrderId")
                            + jsonObject.getString("amount") + jsonObject.getString("realAmount") + jsonObject.getString("payTime") +
                            jsonObject.getString("remark") + byMerIdCache.getPrivateKey();
                    String md5Str = SecureUtil.md5(s);
                    log.info("sixsix callback s" + s);
                    log.info("sixsix callback md5(s) " + md5Str);

                    if (md5Str.equals(sign)) {

                        if ((order.getAmount().doubleValue()) == jsonObject.getDouble("amount").doubleValue()) {

                            int b = platMerOrderService.success(order);

                            if (b > 0) {
                                report(order);
                                log.info("SUCCESS");
                                return "SUCCESS ";
                            } else {
                                log.error("error");
                                return "error";
                            }

                        } else {
                            log.error("sixsix callback amount is error");
                            return "amount is error";
                        }

                    } else {
                        log.error("sixsix callback sign error");
                        return "sign error";
                    }

                } catch (RuntimeException ex) {
                    log.error("sixsix callback notify EpayException", ex);
                    return "error" + ex.getMessage();
                } catch (Exception ex) {
                    log.error("sixsix callback notify Exception", ex);
                    return "system ex ";
                } finally {
                    unlock(orderId);
                }

            } else {
                log.error("sixsix callback plat order id is empty" + orderId);
                return "plat order id is empty";
            }

        } else {
            log.error("sixsix callback plat order is error" + jsonObject.toJSONString());
            return "plat order status is error";
        }

    }

    public String yiPay(JSONObject jsonObject) {
        log.info("yi callback jsonObject " + jsonObject);
        String orderId = jsonObject.getString("out_trade_no");
        String status = jsonObject.getString("code");
        String sign = jsonObject.getString("sign");
        log.info("yi callback orderId={}, status={} sign={}", orderId, status, sign);

        if ("0000".equals(status)) {

            if (!StringUtils.isEmpty(orderId)) {

                try {

                    if (!lock(orderId)) {
                        log.error("yi callback is lock");
                        return "error";
                    }

                    PlatMerOrder order = platMerOrderService.getByOrderId(orderId);
                    if (StringUtils.equals(order.getStat(), "2")) {
                        return "success";
                    }

                    PlatMer byMerIdCache = platMerService.getByMerIdCache(order.getMerId());
                    if (byMerIdCache == null) {
                        return "plat mer is empty not fund";
                    }

                    jsonObject.remove("sign");
//                    jsonObject.remove("nonce_str");
                    jsonObject.remove("sub_msg");
                    jsonObject.remove("code");
                    jsonObject.remove("msg");
                    jsonObject.remove("sub_code");
                    Map<String, Object> map = new TreeMap<>();
                    for (String key : jsonObject.keySet()) {
                        map.put(key, jsonObject.get(key).toString());
                    }
                    String s = convertUrlNotEmpty(map, "&", "=") + "&key=" + byMerIdCache.getPrivateKey();
                    String md5Str = SecureUtil.md5(s).toUpperCase();
                    log.info("yi callback s" + s);
                    log.info("yi callback md5(s) " + md5Str);

                    if (md5Str.equals(sign)) {

                        if ((order.getAmount().doubleValue() * 100) == jsonObject.getDouble("act_amount").doubleValue()) {

                            int b = platMerOrderService.success(order);

                            if (b > 0) {
                                report(order);
                                log.info("success");
                                return "success ";
                            } else {
                                log.error("error");
                                return "error";
                            }

                        } else {
                            log.error("yi callback amount is error");
                            return "amount is error";
                        }

                    } else {
                        log.error("yi callback sign error");
                        return "sign error";
                    }

                } catch (RuntimeException ex) {
                    log.error("yi callback notify EpayException", ex);
                    return "error" + ex.getMessage();
                } catch (Exception ex) {
                    log.error("yi callback notify Exception", ex);
                    return "system ex ";
                } finally {
                    unlock(orderId);
                }

            } else {
                log.error("yi callback plat order id is empty" + orderId);
                return "plat order id is empty";
            }

        } else {
            log.error("yi callback plat order is error" + jsonObject.toJSONString());
            return "plat order status is error";
        }

    }

    public String dongyaPay(JSONObject jsonObject) {
        log.info("dongya callback jsonObject " + jsonObject);
        String orderId = jsonObject.getString("MerchantUniqueOrderId");
        String sign = jsonObject.getString("Sign");
        log.info("dongya callback orderId={}, status={} sign={}", orderId, sign);

//        if ("0000".equals(status)) {

        if (!StringUtils.isEmpty(orderId)) {

            try {

                if (!lock(orderId)) {
                    log.error("dongya callback is lock");
                    return "error";
                }

                PlatMerOrder order = platMerOrderService.getByOrderId(orderId);
                if (StringUtils.equals(order.getStat(), "2")) {
                    return "success";
                }

                PlatMer byMerIdCache = platMerService.getByMerIdCache(order.getMerId());
                if (byMerIdCache == null) {
                    return "plat mer is empty not fund";
                }

                jsonObject.remove("Sign");
                Map<String, Object> map = new TreeMap<>();
                for (String key : jsonObject.keySet()) {
                    map.put(key, jsonObject.get(key).toString());
                }
                String s = convertUrlNotEmpty(map, "&", "=") + byMerIdCache.getPrivateKey();
                String md5Str = SecureUtil.md5(s).toLowerCase();
                log.info("dongya callback s" + s);
                log.info("dongya callback md5(s) " + md5Str);

                if (md5Str.equals(sign)) {

                    if ((order.getAmount().doubleValue()) == jsonObject.getDouble("Amount").doubleValue()) {

                        int b = platMerOrderService.success(order);

                        if (b > 0) {
                            report(order);
                            log.info("SUCCESS");
                            return "SUCCESS";
                        } else {
                            log.error("error");
                            return "error";
                        }

                    } else {
                        log.error("dongya callback amount is error");
                        return "amount is error";
                    }

                } else {
                    log.error("dongya callback sign error");
                    return "sign error";
                }

            } catch (RuntimeException ex) {
                log.error("dongya callback notify EpayException", ex);
                return "error" + ex.getMessage();
            } catch (Exception ex) {
                log.error("dongya callback notify Exception", ex);
                return "system ex ";
            } finally {
                unlock(orderId);
            }

        } else {
            log.error("dongya callback plat order id is empty" + orderId);
            return "plat order id is empty";
        }

//        } else {
//            log.error("dongya callback plat order is error" + jsonObject.toJSONString());
//            return "plat order status is error";
//        }

    }

    public String hengShengPay(JSONObject jsonObject) {
        log.info("hengSheng callback jsonObject " + jsonObject);
        String orderId = jsonObject.getString("mchOrderNo");
        String status = jsonObject.getString("status");
        String sign = jsonObject.getString("sign");
        log.info("hengSheng callback orderId={}, status={} sign={}", orderId, status, sign);

        if ("2".equals(status)) {

            if (!StringUtils.isEmpty(orderId)) {

                try {

                    if (!lock(orderId)) {
                        log.error("hengSheng callback is lock");
                        return "error";
                    }

                    PlatMerOrder order = platMerOrderService.getByOrderId(orderId);
                    if (StringUtils.equals(order.getStat(), "2")) {
                        return "success";
                    }

                    PlatMer byMerIdCache = platMerService.getByMerIdCache(order.getMerId());
                    if (byMerIdCache == null) {
                        return "plat mer is empty not fund";
                    }

                    jsonObject.remove("sign");
                    Map<String, Object> map = new HashMap<>();
                    for (String key : jsonObject.keySet()) {
                        map.put(key, jsonObject.get(key).toString());
                    }
                    String s = convertUrlNotEmpty(map, "&", "=") + "&key=" + byMerIdCache.getPrivateKey();
                    String md5Str = SecureUtil.md5(s).toUpperCase();
                    log.info("hengSheng callback s" + s);
                    log.info("hengSheng callback md5(s) " + md5Str);

                    if (md5Str.equals(sign)) {

                        if ((order.getAmount().doubleValue()) == jsonObject.getDouble("amount").doubleValue()) {

                            int b = platMerOrderService.success(order);

                            if (b > 0) {
                                report(order);
                                log.info("hengSheng success");
                                return "success";
                            } else {
                                log.error("error");
                                return "error";
                            }

                        } else {
                            log.error("hengSheng callback amount is error");
                            return "amount is error";
                        }

                    } else {
                        log.error("hengSheng callback sign error");
                        return "sign error";
                    }

                } catch (RuntimeException ex) {
                    log.error("hengSheng callback notify EpayException", ex);
                    return "error" + ex.getMessage();
                } catch (Exception ex) {
                    log.error("dongya callback notify Exception", ex);
                    return "system ex ";
                } finally {
                    unlock(orderId);
                }

            } else {
                log.error("hengSheng callback plat order id is empty" + orderId);
                return "plat order id is empty";
            }

        } else {
            log.error("hengSheng callback plat order is error" + jsonObject.toJSONString());
            return "plat order status is error";
        }

    }

    public String qpay(JSONObject jsonObject) {
        log.info("pilin jsonObject " + jsonObject);
        String orderId = jsonObject.getString("out_trade_no");
        String status = jsonObject.getString("callbacks");
        String sign = jsonObject.getString("sign");
        log.info(String.format("orderId=%s, status=%s, sign=%s", orderId, status, sign));

        if ("CODE_SUCCESS".equals(status)) {

            if (!StringUtils.isEmpty(orderId)) {

                try {

                    if (!lock(orderId)) {
                        log.error("pilin is lock");
                        return "error";
                    }

                    PlatMerOrder order = platMerOrderService.getByOrderId(orderId);
                    if (StringUtils.equals(order.getStat(), "2")) {
                        return "SUCCESS";
                    }

                    PlatMer byMerIdCache = platMerService.getByMerIdCache(order.getMerId());
                    if (byMerIdCache == null) {
                        return "plat mer is empty not fund";
                    }

                    jsonObject.remove("sign");
                    Map<String, String> map = new TreeMap<>();
                    for (String key : jsonObject.keySet()) {
                        if (null != jsonObject.get(key) && !"".equals(jsonObject.get(key))) {
                            map.put(key, jsonObject.get(key).toString());
                        }
                    }
                    String s = convertUrl(map, "&", "=") + "&key=" + byMerIdCache.getPrivateKey();
                    String md5Str = SecureUtil.md5(s);
                    log.info("s " + s);
                    log.info("md5(s) " + md5Str);

                    if (md5Str.toUpperCase().equals(sign)) {

                        if (order.getAmount().doubleValue() == jsonObject.getDouble("amount_true")) {

                            int b = platMerOrderService.success(order);

                            if (b > 0) {
                                report(order);
                                log.info("ok");
                                return "SUCCESS";
                            } else {
                                log.error("error");
                                return "error";
                            }

                        } else {
                            log.error("amount is error");
                            return "amount is error";
                        }

                    } else {
                        log.error("sign error");
                        return "sign error";
                    }

                } catch (RuntimeException ex) {
                    log.error("notify EpayException", ex);
                    return "error" + ex.getMessage();
                } catch (Exception ex) {
                    log.error("notify Exception", ex);
                    return "system ex ";
                } finally {
                    unlock(orderId);
                }

            } else {
                log.error("plat order id is empty" + orderId);
                return "plat order id is empty";
            }

        } else {
            log.error("plat order is error" + jsonObject.toJSONString());
            return "plat order status is error";
        }

    }

    public String dongyakkpay(JSONObject jsonObject) {

        return caiyingUrl(jsonObject);
    }

    public String ncgepay(JSONObject jsonObject) {
//        String returncode = jsonObject.getString("result");
        String orderid = jsonObject.getString("out_trade_no");
        double amount = jsonObject.getDouble("order_money");
        log.error(" order id " + orderid);
        String sign = jsonObject.getString("sign");
        jsonObject.remove("sign");
        log.error(" order id " + orderid);


//        if (!returncode.equals("Y")) {
//            log.error("plat order is error  status error" + jsonObject.toJSONString());
//            return "plat order is error is status error";
//        }
        if (com.alibaba.druid.util.StringUtils.isEmpty(orderid)) {

            log.error("plat order id is empty notify order" + orderid);
            return "plat order  order id is empty";
        }


        try {
            if (!lock(orderid)) {
                return "error";
            }

            PlatMerOrder byOrderId = platMerOrderService.getByOrderId(orderid);

            if (com.alibaba.druid.util.StringUtils.equals(byOrderId.getStat(), "2")) {
                return "Success";
            }

            double min = byOrderId.getAmount().doubleValue() - 1;
            double max = byOrderId.getAmount().doubleValue() + 1;


            /**
             * 浮动金额
             */
            if (!(amount >= min && amount <= max)) {

//            if (byOrderId.getAmount().doubleValue() != amount) {
                return "amount is  error";
            }

            PlatMer byMerIdCache = platMerService.getByMerIdCache(byOrderId.getMerId());

            if (byMerIdCache == null) {
                return "plat mer is empty not fund";
            }

            String s = "merchantNo=" + jsonObject.getString("merchantNo") + "&money=" + jsonObject.getString("money") + "&order_money=" + jsonObject.getString("order_money") + "&order_num=" + jsonObject.getString("order_num") + "&out_trade_no=" + jsonObject.getString("out_trade_no") + "&pay=" + jsonObject.getString("pay") + "&secret=" + byMerIdCache.getPrivateKey();
            log.error("result sign {}", s);

            if (!SecureUtil.md5(s).toUpperCase().equals(sign)) {

                log.error(" sigin error {}", jsonObject.toJSONString());
                return "sign error";
            }

            byOrderId.setRealAmount(new BigDecimal(amount));
            int b = platMerOrderService.success(byOrderId);
            if (b > 0) {

                report(byOrderId);

                return "Success";
            }
            return "error";

        } catch (Exception ex) {
            log.error("notify EpayException", ex);
            return "error" + ex.getMessage();
        } finally {
            unlock(orderid);
        }
    }

    public String zfb(JSONObject jsonObject) {
        log.info("pilin jsonObject " + jsonObject);
        String orderId = jsonObject.getString("out_trade_no");
        String status = jsonObject.getString("callbacks");
        String sign = jsonObject.getString("sign");
        log.info(String.format("orderId=%s, status=%s, sign=%s", orderId, status, sign));

        if ("CODE_SUCCESS".equals(status)) {

            if (!StringUtils.isEmpty(orderId)) {

                try {

                    if (!lock(orderId)) {
                        log.error("pilin is lock");
                        return "error";
                    }

                    PlatMerOrder order = platMerOrderService.getByOrderId(orderId);
                    if (StringUtils.equals(order.getStat(), "2")) {
                        return "success";
                    }

                    PlatMer byMerIdCache = platMerService.getByMerIdCache(order.getMerId());
                    if (byMerIdCache == null) {
                        return "plat mer is empty not fund";
                    }

                    jsonObject.remove("sign");
                    Map<String, String> map = new TreeMap<>();
                    for (String key : jsonObject.keySet()) {
                        if (null != jsonObject.get(key) && !"".equals(jsonObject.get(key))) {
                            map.put(key, jsonObject.get(key).toString());
                        }
                    }
                    String s = convertUrl(map, "&", "=") + "&key=" + byMerIdCache.getPrivateKey();
                    String md5Str = SecureUtil.md5(s);
                    log.info("s " + s);
                    log.info("md5(s) " + md5Str);

                    if (md5Str.toUpperCase().equals(sign)) {

                        if (order.getAmount().doubleValue() == jsonObject.getDouble("amount")) {

                            int b = platMerOrderService.success(order);

                            if (b > 0) {
                                report(order);
                                log.info("ok");
                                return "success";
                            } else {
                                log.error("error");
                                return "error";
                            }

                        } else {
                            log.error("amount is error order.getAmount().doubleValue()" + order.getAmount().doubleValue());
                            return "amount is error";
                        }

                    } else {
                        log.error("sign error");
                        return "sign error";
                    }

                } catch (RuntimeException ex) {
                    log.error("notify EpayException", ex);
                    return "error" + ex.getMessage();
                } catch (Exception ex) {
                    log.error("notify Exception", ex);
                    return "system ex ";
                } finally {
                    unlock(orderId);
                }

            } else {
                log.error("plat order id is empty" + orderId);
                return "plat order id is empty";
            }

        } else {
            log.error("plat order is error" + jsonObject.toJSONString());
            return "plat order status is error";
        }
    }


    public String chengzi(JSONObject jsonObject) {
        String merchOrder = jsonObject.getString("customno");

        String sign = jsonObject.getString("sign");
        String status = jsonObject.getString("state");
        //message
        jsonObject.remove("sign");
        Map<String, Object> sortedMap = new LinkedHashMap<String, Object>();
        sortedMap.put("merchant", jsonObject.get("merchant").toString());
        sortedMap.put("merchant_money", jsonObject.get("merchant_money").toString());
        sortedMap.put("qrtype", jsonObject.get("qrtype").toString());
        sortedMap.put("customno", jsonObject.get("customno").toString());
        sortedMap.put("sendtime", jsonObject.get("sendtime").toString());
        sortedMap.put("orderno", jsonObject.get("orderno").toString());
        sortedMap.put("money", jsonObject.get("money").toString());
        sortedMap.put("paytime", jsonObject.get("paytime").toString());
        sortedMap.put("state", jsonObject.get("state").toString());

        if (!"1".equals(status)) {
            return "status is error" + merchOrder;

        }
        if (StringUtils.isEmpty(merchOrder)) {

            log.error("plat order id is empty" + merchOrder);
            return "plat order id is empty";
        }

        try {
            if (!lock(merchOrder)) {
                return "error";
            }


            PlatMerOrder byOrderId = platMerOrderService.getByOrderId(merchOrder);

            if (StringUtils.equals(byOrderId.getStat(), "2")) {
                return "OK";
            }

            PlatMer byMerIdCache = platMerService.getByMerIdCache(byOrderId.getMerId());

            if (byMerIdCache == null) {
                return "plat mer is empty not fund";
            }

            String s = convertUrlNotEmpty(sortedMap, "&", "=") + byMerIdCache.getPrivateKey();
//            String sign = SecureUtil.md5(s +"&"+ byMerIdCache.getPrivateKey()).toLowerCase();
            log.error(" sign url error {}", s);
            if (!SecureUtil.md5(s).equals(sign)) {
                return "sign error";
            }


            if (byOrderId.getAmount().doubleValue() != jsonObject.getDouble("money")) {
                return "amount is  error";
            }

            int b = platMerOrderService.success(byOrderId);
            if (b > 0) {
                report(byOrderId);
                log.info("ok");
                return "OK";
            }
            return "error";

        } catch (RuntimeException ex) {
            log.error("notify EpayException", ex);
            return "error" + ex.getMessage();
        } catch (Exception ex) {
            log.error("notify Exception", ex);
            return "system ex ";
        } finally {
            unlock(merchOrder);
        }
    }

    public String hspayUrl(JSONObject jsonObject) {
        String merchOrder = jsonObject.getString("orderid");

        String sign = jsonObject.getString("sign");
        String status = jsonObject.getString("opstate");
        //message
        jsonObject.remove("sign");


        if (!"0".equals(status)) {
            return "status is error" + merchOrder;

        }
        if (StringUtils.isEmpty(merchOrder)) {

            log.error("plat order id is empty" + merchOrder);
            return "plat order id is empty";
        }

        try {
            if (!lock(merchOrder)) {
                return "error";
            }


            PlatMerOrder byOrderId = platMerOrderService.getByOrderId(merchOrder);

            if (StringUtils.equals(byOrderId.getStat(), "2")) {
                return "OK";
            }

            PlatMer byMerIdCache = platMerService.getByMerIdCache(byOrderId.getMerId());

            if (byMerIdCache == null) {
                return "plat mer is empty not fund";
            }

            String s = "orderid=" + jsonObject.getString("orderid") + "&opstate=" + jsonObject.getString("opstate") + "&amount=" + jsonObject.getString("amount") + byMerIdCache.getPrivateKey();
//            String sign = SecureUtil.md5(s +"&"+ byMerIdCache.getPrivateKey()).toLowerCase();
            log.error("");

            log.error(" sign url error {}", s);
            if (!SecureUtil.md5(s).toLowerCase().equals(sign)) {
                return "sign error";
            }


            if (byOrderId.getAmount().doubleValue() != jsonObject.getDouble("amount")) {
                return "amount is  error";
            }

            int b = platMerOrderService.success(byOrderId);
            if (b > 0) {
                report(byOrderId);
                return "OK";
            }
            return "error";

        } catch (RuntimeException ex) {
            log.error("notify EpayException", ex);
            return "error" + ex.getMessage();
        } catch (Exception ex) {
            log.error("notify Exception", ex);
            return "system ex ";
        } finally {
            unlock(merchOrder);
        }
    }

    public String youjiaUrl(JSONObject jsonObject) {
        log.info("pilin jsonObject " + jsonObject);
        String orderId = jsonObject.getString("out_trade_no");
        String status = jsonObject.getString("callbacks");
        String sign = jsonObject.getString("sign");
        log.info(String.format("orderId=%s, status=%s, sign=%s", orderId, status, sign));

        if ("CODE_SUCCESS".equals(status)) {

            if (!StringUtils.isEmpty(orderId)) {

                try {

                    if (!lock(orderId)) {
                        log.error("pilin is lock");
                        return "error";
                    }

                    PlatMerOrder order = platMerOrderService.getByOrderId(orderId);
                    if (StringUtils.equals(order.getStat(), "2")) {
                        return "success";
                    }

                    PlatMer byMerIdCache = platMerService.getByMerIdCache(order.getMerId());
                    if (byMerIdCache == null) {
                        return "plat mer is empty not fund";
                    }

                    jsonObject.remove("sign");
                    Map<String, String> map = new TreeMap<>();
                    for (String key : jsonObject.keySet()) {
                        if (null != jsonObject.get(key) && !"".equals(jsonObject.get(key))) {
                            map.put(key, jsonObject.get(key).toString());
                        }
                    }
                    String s = convertUrl(map, "&", "=") + "&key=" + byMerIdCache.getPrivateKey();
                    String md5Str = SecureUtil.md5(s);
                    log.info("s " + s);
                    log.info("md5(s) " + md5Str);

                    if (md5Str.toUpperCase().equals(sign)) {

                        if (order.getAmount().doubleValue() == jsonObject.getDouble("amount")) {

                            int b = platMerOrderService.success(order);

                            if (b > 0) {
                                report(order);
                                log.info("youjia success");
                                return "success";
                            } else {
                                log.error("error");
                                return "error";
                            }

                        } else {
                            log.error("amount is error");
                            return "amount is error";
                        }

                    } else {
                        log.error("sign error");
                        return "sign error";
                    }

                } catch (RuntimeException ex) {
                    log.error("notify EpayException", ex);
                    return "error" + ex.getMessage();
                } catch (Exception ex) {
                    log.error("notify Exception", ex);
                    return "system ex ";
                } finally {
                    unlock(orderId);
                }

            } else {
                log.error("plat order id is empty" + orderId);
                return "plat order id is empty";
            }

        } else {
            log.error("plat order is error" + jsonObject.toJSONString());
            return "plat order status is error";
        }

    }

    public String baochenUrl(JSONObject jsonObject) {
        log.info("baochen jsonObject " + jsonObject);
        String orderId = jsonObject.getString("orderNo");
        String status = jsonObject.getString("callbacks");
        String sign = jsonObject.getString("sign");
        log.info(String.format("baochen orderId=%s, status=%s, sign=%s", orderId, status, sign));

//        if ("CODE_SUCCESS".equals(status)) {

        if (!StringUtils.isEmpty(orderId)) {

            try {

                if (!lock(orderId)) {
                    log.error("pilin is lock");
                    return "error";
                }

                PlatMerOrder order = platMerOrderService.getByOrderId(orderId);
                if (StringUtils.equals(order.getStat(), "2")) {
                    return "success";
                }

                PlatMer byMerIdCache = platMerService.getByMerIdCache(order.getMerId());
                if (byMerIdCache == null) {
                    return "plat mer is empty not fund";
                }

                jsonObject.remove("sign");
                Map<String, String> map = new TreeMap<>();
                for (String key : jsonObject.keySet()) {
                    if (null != jsonObject.get(key) && !"".equals(jsonObject.get(key))) {
                        map.put(key, jsonObject.get(key).toString());
                    }
                }
                String s = convertUrl(map, "&", "=") + "&key=" + byMerIdCache.getPrivateKey();
                String md5Str = SecureUtil.md5(s);
                log.info("s " + s);
                log.info("md5(s) " + md5Str);

                if (md5Str.equals(sign)) {

                    if (order.getAmount().doubleValue() == jsonObject.getDouble("money")) {

                        int b = platMerOrderService.success(order);

                        if (b > 0) {
                            report(order);
                            log.info("baochen success");
                            return "success";
                        } else {
                            log.error("baochen error");
                            return "error";
                        }

                    } else {
                        log.error("amount is error");
                        return "amount is error";
                    }

                } else {
                    log.error("sign error");
                    return "sign error";
                }

            } catch (RuntimeException ex) {
                log.error("notify EpayException", ex);
                return "error" + ex.getMessage();
            } catch (Exception ex) {
                log.error("notify Exception", ex);
                return "system ex ";
            } finally {
                unlock(orderId);
            }

        } else {
            log.error("plat order id is empty" + orderId);
            return "plat order id is empty";
        }

//        } else {
//            log.error("plat order is error" + jsonObject.toJSONString());
//            return "plat order status is error";
//        }

    }

    public String oreo(JSONObject jsonObject) {
        String merchOrder = jsonObject.getString("MerTradeID");
        String returncode = jsonObject.getString("RtnCode");
        String sign = jsonObject.getString("Sign");
        jsonObject.remove("Sign");
        log.error(" order id " + merchOrder);
        SortedMap sortedMap = new TreeMap();
        for (String key : jsonObject.keySet()) {
            sortedMap.put(key, jsonObject.getString(key));
        }

        if (!returncode.equals("1")) {
            log.error("plat order is error" + jsonObject.toJSONString());
            return "plat order is error";
        }
        if (StringUtils.isEmpty(merchOrder)) {
            log.error("plat order id is empty" + merchOrder);
            return "plat order id is empty";
        }
        try {
            if (!lock(merchOrder)) {
                return "error";
            }
            PlatMerOrder byOrderId = platMerOrderService.getByOrderId(merchOrder);
            if (StringUtils.equals(byOrderId.getStat(), "2")) {
                return "Ok";
            }
            PlatMer byMerIdCache = platMerService.getByMerIdCache(byOrderId.getMerId());
            if (byMerIdCache == null) {
                return "plat mer is empty not fund";
            }
            String s = "Amount=" + jsonObject.getString("Amount") + "&MerProductID=" + jsonObject.getString("MerProductID") + "&MerTradeID=" + jsonObject.getString("MerTradeID") + "&MerUserID=" + jsonObject.getString("MerUserID") + "&Number=" + byMerIdCache.getMerKey() + "&PaymentDate=" + jsonObject.getString("PaymentDate") + "&RtnCode=" + jsonObject.getString("RtnCode") + "&RtnMessage=" + jsonObject.getString("RtnMessage") + "&Key=" + byMerIdCache.getPrivateKey();
            log.info("sign url {}", s);

            log.info("sign url add key {}", s + "&key=" + byMerIdCache.getPrivateKey());
            if (!SecureUtil.md5(s).toLowerCase().equals(sign)) {
                return "sign error";
            }

            if (byOrderId.getAmount().doubleValue() != jsonObject.getDouble("Amount")) {
                return "amount is  error";
            }
            int b = platMerOrderService.success(byOrderId);
            if (b > 0) {
                report(byOrderId);
                return "Ok";
            }
            return "error";

        } catch (RuntimeException ex) {
            log.error("notify EpayException", ex);
            return "error" + ex.getMessage();
        } catch (Exception ex) {
            log.error("notify Exception", ex);
            return "system ex ";
        } finally {
            unlock(merchOrder);
        }

    }

    public String dyUrl(JSONObject jsonObject) {
        log.info("dy jsonObject " + jsonObject);
        String orderId = jsonObject.getString("orderId");
        String status = jsonObject.getString("callbacks");
        String sign = jsonObject.getString("sign");
        log.info(String.format("dy orderId=%s, status=%s, sign=%s", orderId, status, sign));

//        if ("CODE_SUCCESS".equals(status)) {

        if (!StringUtils.isEmpty(orderId)) {

            try {

                if (!lock(orderId)) {
                    log.error("pilin is lock");
                    return "error";
                }

                PlatMerOrder order = platMerOrderService.getByOrderId(orderId);
                if (StringUtils.equals(order.getStat(), "2")) {
                    return "success";
                }

                PlatMer byMerIdCache = platMerService.getByMerIdCache(order.getMerId());
                if (byMerIdCache == null) {
                    return "plat mer is empty not fund";
                }

                jsonObject.remove("sign");
                Map<String, String> map = new TreeMap<>();
                for (String key : jsonObject.keySet()) {
                    map.put(key, jsonObject.get(key).toString());
                }
                String s = convertUrl(map, "&", "=") + byMerIdCache.getPrivateKey();
                String md5Str = SecureUtil.md5(s);
                log.info("s " + s);
                log.info("md5(s) " + md5Str);

                if (md5Str.toLowerCase().equals(sign)) {

                    if (order.getAmount().doubleValue() == jsonObject.getDouble("realAmount")) {

                        int b = platMerOrderService.success(order);

                        if (b > 0) {
                            report(order);
                            log.info("dy success");
                            return "success";
                        } else {
                            log.error("error");
                            return "error";
                        }

                    } else {
                        log.error("amount is error");
                        return "amount is error";
                    }

                } else {
                    log.error("sign error");
                    return "sign error";
                }

            } catch (RuntimeException ex) {
                log.error("notify EpayException", ex);
                return "error" + ex.getMessage();
            } catch (Exception ex) {
                log.error("notify Exception", ex);
                return "system ex ";
            } finally {
                unlock(orderId);
            }

        } else {
            log.error("plat order id is empty" + orderId);
            return "plat order id is empty";
        }
//
//        } else {
//            log.error("plat order is error" + jsonObject.toJSONString());
//            return "plat order status is error";
//        }

    }

    public String xunyinUrl(JSONObject jsonObject) {
        return qfb(jsonObject);
    }

    public String zhongbiUrl(JSONObject jsonObject) {
        String merchOrder = jsonObject.getString("jOrderId");
        String returncode = jsonObject.getString("status");
        String sign = jsonObject.getString("signature");

        if (!returncode.equals("3")) {
            log.error("plat order is error" + jsonObject.toJSONString());
            return "plat order is error";
        }
        if (StringUtils.isEmpty(merchOrder)) {
            log.error("plat order id is empty" + merchOrder);
            return "plat order id is empty";
        }
        try {
            if (!lock(merchOrder)) {
                return "error";
            }
            PlatMerOrder byOrderId = platMerOrderService.getByOrderId(merchOrder);
            if (StringUtils.equals(byOrderId.getStat(), "2")) {
                return "Ok";
            }
            PlatMer byMerIdCache = platMerService.getByMerIdCache(byOrderId.getMerId());
            if (byMerIdCache == null) {
                return "plat mer is empty not fund";
            }

            Map<String, String> verifyMap = new HashMap<>();
            verifyMap.put("status", jsonObject.getString("status"));
            verifyMap.put("jOrderId", jsonObject.getString("jOrderId"));
            verifyMap.put("orderType", jsonObject.getString("orderType"));
            verifyMap.put("amount", jsonObject.getString("amount"));
            verifyMap.put("currency", jsonObject.getString("currency"));
            verifyMap.put("actualAmount", jsonObject.getString("actualAmount"));
            verifyMap.put("fee", jsonObject.getString("fee"));
            verifyMap.put("payWay", jsonObject.getString("payWay"));
            verifyMap.put("payTime", jsonObject.getString("payTime"));
            verifyMap.put("jExtra", jsonObject.getString("jExtra"));
            verifyMap.put("notifyUrl", jsonObject.getString("notifyUrl"));
            verifyMap.put("orderId", jsonObject.getString("orderId"));
            verifyMap.put("signatureMethod", jsonObject.getString("signatureMethod"));
            verifyMap.put("signatureVersion", jsonObject.getString("signatureVersion"));
            verifyMap.put("merchantId", jsonObject.getString("merchantId"));
            verifyMap.put("timestamp", jsonObject.getString("timestamp"));

            String s = DigestUtil.createSign(verifyMap, byMerIdCache.getPrivateKey());

            if (!s.equals(sign)) {
                return "sign error";
            }

            if (byOrderId.getAmount().doubleValue() != jsonObject.getDouble("amount")) {
                return "amount is  error";
            }
            int b = platMerOrderService.success(byOrderId);
            if (b > 0) {
                report(byOrderId);
                log.info("success");
                return "success";
            }
            return "error";

        } catch (RuntimeException ex) {
            log.error("notify EpayException", ex);
            return "error" + ex.getMessage();
        } catch (Exception ex) {
            log.error("notify Exception", ex);
            return "system ex ";
        } finally {
            unlock(merchOrder);
        }

    }

    public String tailianUrl(JSONObject jsonObject) {
        String merchOrder = jsonObject.getString("customer_order");
        String returncode = jsonObject.getString("trading_code");
        String sign = jsonObject.getString("sign_md5");

        if (!returncode.equals("00")) {
            log.error("plat order is error" + jsonObject.toJSONString());
            return "plat order is error";
        }
        if (StringUtils.isEmpty(merchOrder)) {
            log.error("plat order id is empty" + merchOrder);
            return "plat order id is empty";
        }
        try {
            if (!lock(merchOrder)) {
                return "error";
            }
            PlatMerOrder byOrderId = platMerOrderService.getByOrderId(merchOrder);
            if (StringUtils.equals(byOrderId.getStat(), "2")) {
                return "Ok";
            }
            PlatMer byMerIdCache = platMerService.getByMerIdCache(byOrderId.getMerId());
            if (byMerIdCache == null) {
                return "plat mer is empty not fund";
            }

            jsonObject.remove("sign_md5");
            jsonObject.remove("append_fields");
            Map<String, String> map = new TreeMap<>();
            for (String key : jsonObject.keySet()) {
                map.put(key, jsonObject.get(key).toString());
            }
            String s = convertUrl(map, "&", "=") + "&key=" + byMerIdCache.getPrivateKey();

            if (!SecureUtil.md5(s).toUpperCase().equals(sign)) {
                return "sign error";
            }

            if (byOrderId.getAmount().doubleValue() != jsonObject.getDouble("amount")) {
                return "amount is  error";
            }
            int b = platMerOrderService.success(byOrderId);
            if (b > 0) {
                report(byOrderId);
                log.info("OK");
                return "OK";
            }
            return "error";

        } catch (RuntimeException ex) {
            log.error("notify EpayException", ex);
            return "error" + ex.getMessage();
        } catch (Exception ex) {
            log.error("notify Exception", ex);
            return "system ex ";
        } finally {
            unlock(merchOrder);
        }

    }

    public String yonghuapay(JSONObject jsonObject) {
        return yinFuTong(jsonObject);
    }

    public String yinkeUrl(JSONObject jsonObject) {
        return meiruibaoUrl(jsonObject);
    }

    public String baijiaUrl(JSONObject jsonObject) {
        String merchOrder = jsonObject.getString("tranNo");
        String returncode = jsonObject.getString("respCode");
        String sign = jsonObject.getString("sign");

        if (!returncode.equals("1")) {
            log.error("plat order is error" + jsonObject.toJSONString());
            return "plat order is error";
        }
        if (StringUtils.isEmpty(merchOrder)) {
            log.error("plat order id is empty" + merchOrder);
            return "plat order id is empty";
        }
        try {
            if (!lock(merchOrder)) {
                return "error";
            }
            PlatMerOrder byOrderId = platMerOrderService.getByOrderId(merchOrder);
            if (StringUtils.equals(byOrderId.getStat(), "2")) {
                return "Ok";
            }
            PlatMer byMerIdCache = platMerService.getByMerIdCache(byOrderId.getMerId());
            if (byMerIdCache == null) {
                return "plat mer is empty not fund";
            }

            jsonObject.remove("sign");
            Map<String, String> map = new TreeMap<>();
            for (String key : jsonObject.keySet()) {
                map.put(key, jsonObject.get(key).toString());
            }
            String s = convertUrl(map, "&", "=") + byMerIdCache.getPrivateKey();

            if (!SecureUtil.md5(s).equals(sign)) {
                return "sign error";
            }

            if (byOrderId.getAmount().doubleValue() != jsonObject.getDouble("tranAmt")) {
                return "amount is  error";
            }
            int b = platMerOrderService.success(byOrderId);
            if (b > 0) {
                report(byOrderId);
                log.info("OK");
                return "000000";
            }
            return "error";

        } catch (RuntimeException ex) {
            log.error("notify EpayException", ex);
            return "error" + ex.getMessage();
        } catch (Exception ex) {
            log.error("notify Exception", ex);
            return "system ex ";
        } finally {
            unlock(merchOrder);
        }

    }

    public String anranUrl(JSONObject jsonObject) {
        log.info("jsonObject {}", jsonObject);

        String merchOrder = jsonObject.getString("outOrderId");
        String returncode = jsonObject.getString("respCode");
        String sign = jsonObject.getString("sign");

//        if (!returncode.equals("1")) {
//            log.error("plat order is error" + jsonObject.toJSONString());
//            return "plat order is error";
//        }
        if (StringUtils.isEmpty(merchOrder)) {
            log.error("plat order id is empty" + merchOrder);
            return "plat order id is empty";
        }
        try {
            if (!lock(merchOrder)) {
                return "error";
            }
            PlatMerOrder byOrderId = platMerOrderService.getByOrderId(merchOrder);
            if (StringUtils.equals(byOrderId.getStat(), "2")) {
                return "Ok";
            }
            PlatMer byMerIdCache = platMerService.getByMerIdCache(byOrderId.getMerId());
            if (byMerIdCache == null) {
                return "plat mer is empty not fund";
            }

            //拼接参数
            String plaintext = "appKey=" + byMerIdCache.getMerKey()
                    + "outOrderId=" + jsonObject.getString("outOrderId")
                    + "orderFund=" + jsonObject.getString("orderFund")
                    + "orderId=" + jsonObject.getString("orderId")
                    + "realOrderFund=" + jsonObject.getString("realOrderFund")
                    + "key=" + byMerIdCache.getPrivateKey();

            log.info("s {}", plaintext);

            // 加签 MD5工具类使用通用的就行
            String s = SecureUtil.md5(plaintext).toLowerCase();

            log.info("sign {}", s);

            if (!s.equals(sign)) {
                return "sign error";
            }

            if (byOrderId.getAmount().doubleValue() != jsonObject.getDouble("orderFund")) {
                return "amount is  error";
            }
            int b = platMerOrderService.success(byOrderId);
            if (b > 0) {
                report(byOrderId);
                log.info("OK");
                return "success";
            }
            return "error";

        } catch (RuntimeException ex) {
            log.error("notify EpayException", ex);
            return "error" + ex.getMessage();
        } catch (Exception ex) {
            log.error("notify Exception", ex);
            return "system ex ";
        } finally {
            unlock(merchOrder);
        }

    }

    public String yooopay(JSONObject jsonObject) {
        return yinFuTong(jsonObject);
    }

    public String yjapy(JSONObject jsonObject) {
        return pilinUrl(jsonObject);
    }

    public String hfpay(JSONObject jsonObject) {
        return yinFuTong(jsonObject);
    }

    public String acUrl(JSONObject jsonObject) {

        return kuaizhifuUrl(jsonObject);
    }

    public String kuaizhifuUrl(JSONObject jsonObject) {
        log.info("kuaizhifu jsonObject " + jsonObject);
        String orderId = jsonObject.getString("out_trade_no");
        String status = jsonObject.getString("status");
        String sign = jsonObject.getString("sign");
        log.info(String.format("dy orderId=%s, status=%s, sign=%s", orderId, status, sign));

        if ("1".equals(status)) {

            if (!StringUtils.isEmpty(orderId)) {

                try {

                    if (!lock(orderId)) {
                        log.error("pilin is lock");
                        return "error";
                    }

                    PlatMerOrder order = platMerOrderService.getByOrderId(orderId);
                    if (StringUtils.equals(order.getStat(), "2")) {
                        return "success";
                    }

                    PlatMer byMerIdCache = platMerService.getByMerIdCache(order.getMerId());
                    if (byMerIdCache == null) {
                        return "plat mer is empty not fund";
                    }

                    jsonObject.remove("sign");
                    jsonObject.remove("sign_type");
                    Map<String, String> map = new TreeMap<>();
                    for (String key : jsonObject.keySet()) {
                        map.put(key, jsonObject.get(key).toString());
                    }
                    String s = convertUrl(map, "&", "=") + "&" + byMerIdCache.getPrivateKey();
                    String md5Str = SecureUtil.md5(s).toLowerCase();
                    log.info("s " + s);
                    log.info("md5(s) " + md5Str);

                    if (md5Str.equals(sign)) {

                        if (order.getAmount().doubleValue() == jsonObject.getDouble("total_fee")) {

                            int b = platMerOrderService.success(order);

                            if (b > 0) {
                                report(order);
                                log.info("kuaizhifu success");
                                return "success";
                            } else {
                                log.error("error");
                                return "error";
                            }

                        } else {
                            log.error("amount is error");
                            return "amount is error";
                        }

                    } else {
                        log.error("sign error");
                        return "sign error";
                    }

                } catch (RuntimeException ex) {
                    log.error("notify EpayException", ex);
                    return "error" + ex.getMessage();
                } catch (Exception ex) {
                    log.error("notify Exception", ex);
                    return "system ex ";
                } finally {
                    unlock(orderId);
                }

            } else {
                log.error("plat order id is empty" + orderId);
                return "plat order id is empty";
            }

        } else {
            log.error("plat order is error" + jsonObject.toJSONString());
            return "plat order status is error";
        }

    }

    public String luoyaoUrl(JSONObject jsonObject) {
        return tianxie(jsonObject);
    }

    public String jjzfUrl(JSONObject jsonObject) {
        log.info("kuaizhifu jsonObject " + jsonObject);
        String orderId = jsonObject.getJSONObject("data").getString("order_no");
        String status = jsonObject.getJSONObject("data").getString("status");
        String sign = jsonObject.getString("sign");
        log.info(String.format("dy orderId=%s, status=%s, sign=%s", orderId, status, sign));

        if ("1000".equals(status)) {

            if (!StringUtils.isEmpty(orderId)) {

                try {

                    if (!lock(orderId)) {
                        log.error("pilin is lock");
                        return "error";
                    }

                    PlatMerOrder order = platMerOrderService.getByOrderId(orderId);
                    if (StringUtils.equals(order.getStat(), "2")) {
                        return "success";
                    }

                    PlatMer byMerIdCache = platMerService.getByMerIdCache(order.getMerId());
                    if (byMerIdCache == null) {
                        return "plat mer is empty not fund";
                    }

                    jsonObject.remove("sign");
                    jsonObject.remove("sign_type");
                    Map<String, String> map = new TreeMap<>();
                    for (String key : jsonObject.keySet()) {


                        if (key.equals("data")) {
                            for (String datakey : jsonObject.getJSONObject("data").keySet()) {

                                map.put(datakey, jsonObject.getJSONObject("data").get(datakey).toString());
                            }
                        } else {
                            map.put(key, jsonObject.get(key).toString());
                        }
                    }
                    String s = convertUrl(map, "&", "=") + "&key=" + byMerIdCache.getPrivateKey();
                    String md5Str = SecureUtil.md5(s).toUpperCase();
                    log.info("s " + s);
                    log.info("md5(s) " + md5Str);

                    if (md5Str.equals(sign)) {

                        if (order.getAmount().doubleValue() == jsonObject.getJSONObject("data").getDouble("amount")) {

                            int b = platMerOrderService.success(order);

                            if (b > 0) {
                                report(order);
                                log.info("kuaizhifu success");
                                return "success";
                            } else {
                                log.error("error");
                                return "error";
                            }

                        } else {
                            log.error("amount is error");
                            return "amount is error";
                        }

                    } else {
                        log.error("sign error");
                        return "sign error";
                    }

                } catch (RuntimeException ex) {
                    log.error("notify EpayException", ex);
                    return "error" + ex.getMessage();
                } catch (Exception ex) {
                    log.error("notify Exception", ex);
                    return "system ex ";
                } finally {
                    unlock(orderId);
                }

            } else {
                log.error("plat order id is empty" + orderId);
                return "plat order id is empty";
            }

        } else {
            log.error("plat order is error" + jsonObject.toJSONString());
            return "plat order status is error";
        }

    }
    public String dongPay(JSONObject jsonObject) {
        log.info("shun callback jsonObject " + jsonObject);
        String orderId = jsonObject.getString("mchOrderNo");
        String status = jsonObject.getString("status");
        String sign = jsonObject.getString("sign");
        log.info(String.format("shun callback orderId=%s, status=%s, sign=%s", orderId, status, sign));

        if ("2".equals(status)) {

            if (!StringUtils.isEmpty(orderId)) {

                try {

                    if (!lock(orderId)) {
                        log.error("shun callback is lock");
                        return "error";
                    }

                    PlatMerOrder order = platMerOrderService.getByOrderId(orderId);
                    if (StringUtils.equals(order.getStat(), "2")) {
                        log.info("shun callback order success");
                        return "success";
                    }

                    PlatMer byMerIdCache = platMerService.getByMerIdCache(order.getMerId());
                    if (byMerIdCache == null) {
                        log.info("shun callback plat mer is empty not fund");
                        return "plat mer is empty not fund";
                    }

                    jsonObject.remove("sign");
                    SortedMap sortedMap = new TreeMap();
                    for (String key : jsonObject.keySet()) {
                        sortedMap.put(key, jsonObject.getString(key));
                    }
                    String s = convertUrlNotEmpty(sortedMap, "&", "=") + "&key=" + byMerIdCache.getPrivateKey();
                    String md5Str = SecureUtil.md5(s).toUpperCase();

                    log.info("shun s " + s);
                    log.info("shun md5(s) " + md5Str);

                    if (md5Str.equals(sign)) {

                        if (order.getAmount().doubleValue() == (jsonObject.getDouble("amount") / 100)) {

                            int b = platMerOrderService.success(order);

                            if (b > 0) {
                                log.info("shun launch success");

                                report(order);
                                log.info("success");
                                return "success";
                            } else {
                                log.error("shun callback error");
                                return "error";
                            }

                        } else {
                            log.error("shun callback amount is error");
                            return "amount is error";
                        }

                    } else {
                        log.error("shun callback sign error");
                        return "sign error";
                    }

                } catch (RuntimeException ex) {
                    log.error("shun callback notify EpayException", ex);
                    return "error" + ex.getMessage();
                } catch (Exception ex) {
                    log.error("jinxin callback notify Exception", ex);
                    return "system ex ";
                } finally {
                    unlock(orderId);
                }

            } else {
                log.error("shun callback plat order id is empty" + orderId);
                return "plat order id is empty";
            }

        } else {
            log.error("shun callback plat order is error" + jsonObject.toJSONString());
            return "plat order status is error";
        }
    }
    public String shunUrl(JSONObject jsonObject) {
        log.info("shun callback jsonObject " + jsonObject);
        String orderId = jsonObject.getString("mchOrderNo");
        String status = jsonObject.getString("status");
        String sign = jsonObject.getString("sign");
        log.info(String.format("shun callback orderId=%s, status=%s, sign=%s", orderId, status, sign));

        if ("2".equals(status)) {

            if (!StringUtils.isEmpty(orderId)) {

                try {

                    if (!lock(orderId)) {
                        log.error("shun callback is lock");
                        return "error";
                    }

                    PlatMerOrder order = platMerOrderService.getByOrderId(orderId);
                    if (StringUtils.equals(order.getStat(), "2")) {
                        log.info("shun callback order success");
                        return "success";
                    }

                    PlatMer byMerIdCache = platMerService.getByMerIdCache(order.getMerId());
                    if (byMerIdCache == null) {
                        log.info("shun callback plat mer is empty not fund");
                        return "plat mer is empty not fund";
                    }

                    jsonObject.remove("sign");
                    SortedMap sortedMap = new TreeMap();
                    for (String key : jsonObject.keySet()) {
                        sortedMap.put(key, jsonObject.getString(key));
                    }
                    String s = convertUrlNotEmpty(sortedMap, "&", "=") + "&key=" + byMerIdCache.getPrivateKey();
                    String md5Str = SecureUtil.md5(s).toUpperCase();

                    log.info("shun s " + s);
                    log.info("shun md5(s) " + md5Str);

                    if (md5Str.equals(sign)) {

                        if (order.getAmount().doubleValue() == (jsonObject.getDouble("amount") / 100)) {

                            int b = platMerOrderService.success(order);

                            if (b > 0) {
                                log.info("shun launch success");

                                report(order);
                                log.info("success");
                                return "success";
                            } else {
                                log.error("shun callback error");
                                return "error";
                            }

                        } else {
                            log.error("shun callback amount is error");
                            return "amount is error";
                        }

                    } else {
                        log.error("shun callback sign error");
                        return "sign error";
                    }

                } catch (RuntimeException ex) {
                    log.error("shun callback notify EpayException", ex);
                    return "error" + ex.getMessage();
                } catch (Exception ex) {
                    log.error("jinxin callback notify Exception", ex);
                    return "system ex ";
                } finally {
                    unlock(orderId);
                }

            } else {
                log.error("shun callback plat order id is empty" + orderId);
                return "plat order id is empty";
            }

        } else {
            log.error("shun callback plat order is error" + jsonObject.toJSONString());
            return "plat order status is error";
        }
    }

    public String facaiUrl(JSONObject jsonObject) {
        log.info("shun callback jsonObject " + jsonObject);
        String orderId = jsonObject.getString("transactionId");
        String status = jsonObject.getString("status");
        String sign = jsonObject.getString("sign");
        log.info(String.format("facai callback orderId=%s, status=%s, sign=%s", orderId, status, sign));

        if ("3".equals(status)) {

            if (!StringUtils.isEmpty(orderId)) {

                try {

                    if (!lock(orderId)) {
                        log.error("facai callback is lock");
                        return "error";
                    }

                    PlatMerOrder order = platMerOrderService.getByOrderId(orderId);
                    if (StringUtils.equals(order.getStat(), "2")) {
                        log.info("facai callback order success");
                        return "success";
                    }

                    PlatMer byMerIdCache = platMerService.getByMerIdCache(order.getMerId());
                    if (byMerIdCache == null) {
                        log.info("facai callback plat mer is empty not fund");
                        return "plat mer is empty not fund";
                    }

                    jsonObject.remove("sign");
                    SortedMap sortedMap = new TreeMap();
                    for (String key : jsonObject.keySet()) {
                        sortedMap.put(key, jsonObject.getString(key));
                    }
                    String s = byMerIdCache.getPrivateKey() + "&" + convertUrlNotEmpty(sortedMap, "&", "=");
                    String md5Str = SecureUtil.md5(s);

                    log.info("facai s " + s);
                    log.info("facai md5(s) " + md5Str);

                    if (md5Str.equals(sign)) {

                        if (order.getAmount().doubleValue() == (jsonObject.getDouble("amount") / 100)) {

                            int b = platMerOrderService.success(order);

                            if (b > 0) {
                                log.info("shun launch success");

                                report(order);
                                log.info("success");
                                return "success";
                            } else {
                                log.error("facai callback error");
                                return "error";
                            }

                        } else {
                            log.error("facai callback amount is error");
                            return "amount is error";
                        }

                    } else {
                        log.error("facai callback sign error");
                        return "sign error";
                    }

                } catch (RuntimeException ex) {
                    log.error("facai callback notify EpayException", ex);
                    return "error" + ex.getMessage();
                } catch (Exception ex) {
                    log.error("facai callback notify Exception", ex);
                    return "system ex ";
                } finally {
                    unlock(orderId);
                }

            } else {
                log.error("facai callback plat order id is empty" + orderId);
                return "plat order id is empty";
            }

        } else {
            log.error("facai callback plat order is error" + jsonObject.toJSONString());
            return "plat order status is error";
        }
    }

    public String rrfUrl(JSONObject jsonObject) {
        log.info("shun callback jsonObject " + jsonObject);
        String orderId = jsonObject.getString("orderid");
        String status = jsonObject.getString("returncode");
        String sign = jsonObject.getString("sign");
        log.info(String.format("rrf callback orderId=%s, status=%s, sign=%s", orderId, status, sign));

        if ("00".equals(status)) {

            if (!StringUtils.isEmpty(orderId)) {

                try {

                    if (!lock(orderId)) {
                        log.error("rrf callback is lock");
                        return "error";
                    }

                    PlatMerOrder order = platMerOrderService.getByOrderId(orderId);
                    if (StringUtils.equals(order.getStat(), "2")) {
                        log.info("rrf callback order success");
                        return "success";
                    }

                    PlatMer byMerIdCache = platMerService.getByMerIdCache(order.getMerId());
                    if (byMerIdCache == null) {
                        log.info("rrf callback plat mer is empty not fund");
                        return "plat mer is empty not fund";
                    }

                    jsonObject.remove("sign");
                    SortedMap sortedMap = new TreeMap();
                    for (String key : jsonObject.keySet()) {
                        sortedMap.put(key, jsonObject.getString(key));
                    }
                    String s = convertUrlNotEmpty(sortedMap, "&", "=") + "&key=" + byMerIdCache.getPrivateKey();
                    String md5Str = SecureUtil.md5(s).toUpperCase();

                    log.info("rrf s " + s);
                    log.info("rrf md5(s) " + md5Str);

                    if (md5Str.equals(sign)) {

                        if (order.getAmount().doubleValue() == (jsonObject.getDouble("amount"))) {

                            int b = platMerOrderService.success(order);

                            if (b > 0) {
                                log.info("rrf launch success");

                                report(order);
                                log.info("OK");
                                return "OK";
                            } else {
                                log.error("rrf callback error");
                                return "error";
                            }

                        } else {
                            log.error("rrf callback amount is error");
                            return "amount is error";
                        }

                    } else {
                        log.error("rrf callback sign error");
                        return "sign error";
                    }

                } catch (RuntimeException ex) {
                    log.error("rrf callback notify EpayException", ex);
                    return "error" + ex.getMessage();
                } catch (Exception ex) {
                    log.error("rrf callback notify Exception", ex);
                    return "system ex ";
                } finally {
                    unlock(orderId);
                }

            } else {
                log.error("rrf callback plat order id is empty" + orderId);
                return "plat order id is empty";
            }

        } else {
            log.error("rrf callback plat order is error" + jsonObject.toJSONString());
            return "plat order status is error";
        }
    }

    public String chachaUrl(JSONObject jsonObject) {
        log.info("chacha callback jsonObject " + jsonObject);
        String orderId = jsonObject.getString("orderid");
        String status = jsonObject.getString("retcode");
        String sign = jsonObject.getString("sign");
        log.info(String.format("chacha callback orderId=%s, status=%s, sign=%s", orderId, status, sign));

        if ("00".equals(status)) {

            if (!StringUtils.isEmpty(orderId)) {

                try {

                    if (!lock(orderId)) {
                        log.error("chacha callback is lock");
                        return "error";
                    }

                    PlatMerOrder order = platMerOrderService.getByOrderId(orderId);
                    if (StringUtils.equals(order.getStat(), "2")) {
                        log.info("chacha callback order success");
                        return "success";
                    }

                    PlatMer byMerIdCache = platMerService.getByMerIdCache(order.getMerId());
                    if (byMerIdCache == null) {
                        log.info("chacha callback plat mer is empty not fund");
                        return "plat mer is empty not fund";
                    }

                    String s = jsonObject.getString("timestamp") + byMerIdCache.getPrivateKey();
                    String md5Str = SecureUtil.md5(s).toLowerCase();

                    log.info("chacha s " + s);
                    log.info("chacha md5(s) " + md5Str);

                    if (md5Str.equals(sign)) {

                        if (order.getAmount().doubleValue() == (jsonObject.getDouble("money"))) {

                            int b = platMerOrderService.success(order);

                            if (b > 0) {
                                log.info("chacha launch success");

                                report(order);
                                log.info("chacha OK");
                                return "OK";
                            } else {
                                log.error("chacha callback error");
                                return "error";
                            }

                        } else {
                            log.error("chacha callback amount is error");
                            return "amount is error";
                        }

                    } else {
                        log.error("chacha sign error");
                        return "sign error";
                    }

                } catch (RuntimeException ex) {
                    log.error("chacha notify EpayException", ex);
                    return "error" + ex.getMessage();
                } catch (Exception ex) {
                    log.error("chacha callback notify Exception", ex);
                    return "system ex ";
                } finally {
                    unlock(orderId);
                }

            } else {
                log.error("chacha callback plat order id is empty" + orderId);
                return "plat order id is empty";
            }

        } else {
            log.error("chacha callback plat order is error" + jsonObject.toJSONString());
            return "plat order status is error";
        }
    }

    public String jsUrl(JSONObject jsonObject) {
        log.info("jsUrl callback jsonObject " + jsonObject);
        String orderId = jsonObject.getString("biz_order_no");
        String status = jsonObject.getString("biz_code");
        String sign = jsonObject.getString("sign");
        log.info(String.format("jsUrl callback orderId=%s, status=%s, sign=%s", orderId, status, sign));

        if ("05".equals(status)) {

            if (!StringUtils.isEmpty(orderId)) {

                try {

                    if (!lock(orderId)) {
                        log.error("jsUrl callback is lock");
                        return "error";
                    }

                    PlatMerOrder order = platMerOrderService.getByOrderId(orderId);
                    if (StringUtils.equals(order.getStat(), "2")) {
                        log.info("jsUrl callback order success");
                        return "success";
                    }

                    PlatMer byMerIdCache = platMerService.getByMerIdCache(order.getMerId());
                    if (byMerIdCache == null) {
                        log.info("jsUrl callback plat mer is empty not fund");
                        return "plat mer is empty not fund";
                    }

                    jsonObject.remove("sign");
                    SortedMap sortedMap = new TreeMap();
                    for (String key : jsonObject.keySet()) {
                        sortedMap.put(key, jsonObject.getString(key));
                    }
                    sortedMap.put("key", byMerIdCache.getPrivateKey());
                    String s = convertUrlNotEmpty(sortedMap, "&", "=");
                    String md5Str = SecureUtil.md5(s);

                    log.info("jsUrl s " + s);
                    log.info("jsUrl md5(s) " + md5Str);

                    if (md5Str.equals(sign)) {

                        if (order.getAmount().doubleValue() == (jsonObject.getDouble("order_amount") / 100)) {

                            int b = platMerOrderService.success(order);

                            if (b > 0) {
                                log.info("chacha launch success");

                                report(order);
                                log.info("chacha OK");
                                return "success";
                            } else {
                                log.error("chacha callback error");
                                return "error";
                            }

                        } else {
                            log.error("chacha callback amount is error");
                            return "amount is error";
                        }

                    } else {
                        log.error("jsUrl sign error");
                        return "sign error";
                    }

                } catch (RuntimeException ex) {
                    log.error("jsUrl notify EpayException", ex);
                    return "error" + ex.getMessage();
                } catch (Exception ex) {
                    log.error("jsUrl callback notify Exception", ex);
                    return "system ex ";
                } finally {
                    unlock(orderId);
                }

            } else {
                log.error("jsUrl callback plat order id is empty" + orderId);
                return "plat order id is empty";
            }

        } else {
            log.error("jsUrl callback plat order is error" + jsonObject.toJSONString());
            return "plat order status is error";
        }
    }

    public String yishengUrl(JSONObject jsonObject) {
        return dongyayihao(jsonObject);
    }

    public String shrpayUrl(JSONObject jsonObject) {
        return dongyayihao(jsonObject);
    }

    public String huanyuUrl(JSONObject jsonObject) {
        log.info("chacha callback jsonObject " + jsonObject);
        String orderId = jsonObject.getString("orderNo");
        String sign = jsonObject.getString("sign");
        log.info(String.format("chacha callback orderId=%s,sign=%s", orderId, sign));

        if (!StringUtils.isEmpty(orderId)) {

            try {

                if (!lock(orderId)) {
                    log.error("chacha callback is lock");
                    return "error";
                }

                PlatMerOrder order = platMerOrderService.getByOrderId(orderId);
                if (StringUtils.equals(order.getStat(), "2")) {
                    log.info("chacha callback order success");
                    return "success";
                }

                PlatMer byMerIdCache = platMerService.getByMerIdCache(order.getMerId());
                if (byMerIdCache == null) {
                    log.info("chacha callback plat mer is empty not fund");
                    return "plat mer is empty not fund";
                }

                jsonObject.remove("sign");
                SortedMap sortedMap = new TreeMap();
                for (String key : jsonObject.keySet()) {
                    sortedMap.put(key, jsonObject.getString(key));
                }
                String s = convertUrlNotEmpty(sortedMap, "&", "=") + "&key=" + byMerIdCache.getPrivateKey();
                String md5Str = SecureUtil.md5(s);

                log.info("chacha s " + s);
                log.info("chacha md5(s) " + md5Str);

                if (md5Str.equals(sign)) {

                    if (order.getAmount().doubleValue() == (jsonObject.getDouble("money"))) {

                        int b = platMerOrderService.success(order);

                        if (b > 0) {
                            log.info("chacha launch success");

                            report(order);
                            log.info("chacha success");
                            return "success";
                        } else {
                            log.error("chacha callback error");
                            return "error";
                        }

                    } else {
                        log.error("chacha callback amount is error");
                        return "amount is error";
                    }

                } else {
                    log.error("chacha sign error");
                    return "sign error";
                }

            } catch (RuntimeException ex) {
                log.error("chacha notify EpayException", ex);
                return "error" + ex.getMessage();
            } catch (Exception ex) {
                log.error("chacha callback notify Exception", ex);
                return "system ex ";
            } finally {
                unlock(orderId);
            }
        } else {
            log.error("chacha callback plat order is error" + jsonObject.toJSONString());
            return "plat order status is error";
        }
    }

    public String dahengUrl(JSONObject jsonObject) {
        return juzi(jsonObject);
    }

    public String fajiaUrl(JSONObject jsonObject) {
        log.info("fajia callback jsonObject " + jsonObject);
        String orderId = jsonObject.getString("out_order_no");
//        String status = jsonObject.getString("biz_code");
        String sign = jsonObject.getString("sign");
        log.info(String.format("fajia callback orderId=%s, sign=%s", orderId, sign));

//        if ("05".equals(status)) {

        if (!StringUtils.isEmpty(orderId)) {

            try {

                if (!lock(orderId)) {
                    log.error("fajia callback is lock");
                    return "error";
                }

                PlatMerOrder order = platMerOrderService.getByOrderId(orderId);
                if (StringUtils.equals(order.getStat(), "2")) {
                    log.info("fajia callback order success");
                    return "success";
                }

                PlatMer byMerIdCache = platMerService.getByMerIdCache(order.getMerId());
                if (byMerIdCache == null) {
                    log.info("fajia callback plat mer is empty not fund");
                    return "plat mer is empty not fund";
                }

                jsonObject.remove("sign");
                SortedMap sortedMap = new TreeMap();
                for (String key : jsonObject.keySet()) {
                    if ("amount".equals(key)) {
                        sortedMap.put(key, new DecimalFormat("0.00").format(new BigDecimal(jsonObject.getString(key))));
                    } else {
                        sortedMap.put(key, jsonObject.getString(key));
                    }
                }
                String s = convertUrlNotEmpty(sortedMap, "&", "=") + byMerIdCache.getPrivateKey();
                String md5Str = SecureUtil.md5(s);

                log.info("jsfajiaUrl s " + s);
                log.info("fajia md5(s) " + md5Str);

                if (md5Str.equals(sign)) {

                    if (order.getAmount().doubleValue() == (jsonObject.getDouble("amount"))) {

                        int b = platMerOrderService.success(order);

                        if (b > 0) {
                            log.info("fajia launch success");

                            report(order);
                            log.info("fajia OK");
                            return "{\"code\":0, \"msg\":\"success\"}";
                        } else {
                            log.error("fajia callback error");
                            return "error";
                        }

                    } else {
                        log.error("fajia callback amount is error");
                        return "amount is error";
                    }

                } else {
                    log.error("fajia sign error");
                    return "sign error";
                }

            } catch (RuntimeException ex) {
                log.error("fajia notify EpayException", ex);
                return "error" + ex.getMessage();
            } catch (Exception ex) {
                log.error("fajia callback notify Exception", ex);
                return "system ex ";
            } finally {
                unlock(orderId);
            }

        } else {
            log.error("fajia callback plat order id is empty" + orderId);
            return "plat order id is empty";
        }

//        } else {
//            log.error("jsUrl callback plat order is error" + jsonObject.toJSONString());
//            return "plat order status is error";
//        }
    }

    public String haitunUrl(JSONObject jsonObject) {
        log.info("jsUrl callback jsonObject " + jsonObject);
        String orderId = jsonObject.getString("num");
//        String status = jsonObject.getString("biz_code");
        String sign = jsonObject.getString("sign");
        log.info(String.format("jsUrl callback orderId=%s, sign=%s", orderId, sign));

//        if ("05".equals(status)) {

        if (!StringUtils.isEmpty(orderId)) {

            try {

                if (!lock(orderId)) {
                    log.error("jsUrl callback is lock");
                    return "error";
                }

                PlatMerOrder order = platMerOrderService.getByOrderId(orderId);
                if (StringUtils.equals(order.getStat(), "2")) {
                    log.info("jsUrl callback order success");
                    return "success";
                }

                PlatMer byMerIdCache = platMerService.getByMerIdCache(order.getMerId());
                if (byMerIdCache == null) {
                    log.info("jsUrl callback plat mer is empty not fund");
                    return "plat mer is empty not fund";
                }

                String s = byMerIdCache.getPrivateKey() + jsonObject.getString("num") + jsonObject.getString("money") + jsonObject.getString("uid");


                String md5Str = SecureUtil.md5(s);

                log.info("jsUrl s " + s);
                log.info("jsUrl md5(s) " + md5Str);

                if (md5Str.equals(sign)) {

                    if (order.getAmount().doubleValue() == (jsonObject.getDouble("money").intValue())) {

                        int b = platMerOrderService.success(order);

                        if (b > 0) {
                            log.info("chacha launch success");

                            report(order);
                            log.info("chacha success");
                            return "success";
                        } else {
                            log.error("chacha callback error");
                            return "error";
                        }

                    } else {
                        log.error("chacha callback amount is error");
                        return "amount is error";
                    }

                } else {
                    log.error("jsUrl sign error");
                    return "sign error";
                }

            } catch (RuntimeException ex) {
                log.error("jsUrl notify EpayException", ex);
                return "error" + ex.getMessage();
            } catch (Exception ex) {
                log.error("jsUrl callback notify Exception", ex);
                return "system ex ";
            } finally {
                unlock(orderId);
            }

        } else {
            log.error("jsUrl callback plat order id is empty" + orderId);
            return "plat order id is empty";
        }
    }

    public String hongyunUrl(JSONObject jsonObject) {
        log.info("hongyun callback jsonObject " + jsonObject);
        String orderId = jsonObject.getString("merchant_order_id");
        String status = jsonObject.getString("status");
        String sign = jsonObject.getString("appSecret");
        log.info(String.format("hongyun callback orderId=%s,sign=%s, status=%s", orderId, sign, sign));

        if (!StringUtils.isEmpty(orderId)) {

            try {

                if (!lock(orderId)) {
                    log.error("hongyun callback is lock");
                    return "error";
                }

                PlatMerOrder order = platMerOrderService.getByOrderId(orderId);
                if (StringUtils.equals(order.getStat(), "2")) {
                    log.info("hongyun callback order success");
                    return "success";
                }

                PlatMer byMerIdCache = platMerService.getByMerIdCache(order.getMerId());
                if (byMerIdCache == null) {
                    log.info("hongyun callback plat mer is empty not fund");
                    return "plat mer is empty not fund";
                }

                String s = "merchantID=" + jsonObject.getString("merchant_id") + "&merchantOrderCode=" + jsonObject.getString("merchant_order_id") +
                        "&totalAmount=" + jsonObject.getString("total_amount") + "&paymentState=" + jsonObject.getString("status") + "&orderCode=" + jsonObject.getString("order_code") +
                        "&tradeNo=" + jsonObject.getString("trade_no") + "&tradeDate=" + jsonObject.getString("trade_time") + "&MD5Str=" + byMerIdCache.getPrivateKey();
                String md5Str = SecureUtil.md5(s).toUpperCase();

                log.info("hongyun s " + s);
                log.info("hongyun md5(s) " + md5Str);

                if (md5Str.equals(sign)) {

                    if (order.getAmount().doubleValue() == (jsonObject.getDouble("total_amount"))) {

                        int b = platMerOrderService.success(order);

                        if (b > 0) {
                            log.info("hongyun launch success");

                            report(order);
                            log.info("hongyun success");
                            return "";
                        } else {
                            log.error("hongyun callback error");
                            return "error";
                        }

                    } else {
                        log.error("hongyun callback amount is error");
                        return "amount is error";
                    }

                } else {
                    log.error("hongyun sign error");
                    return "sign error";
                }

            } catch (RuntimeException ex) {
                log.error("hongyun notify EpayException", ex);
                return "error" + ex.getMessage();
            } catch (Exception ex) {
                log.error("hongyun callback notify Exception", ex);
                return "system ex ";
            } finally {
                unlock(orderId);
            }
        } else {
            log.error("hongyun callback plat order is error" + jsonObject.toJSONString());
            return "plat order status is error";
        }
    }


    public String yunpayUrl(JSONObject param) {
        return yinFuTong(param);
    }

    public String haofuUrl(JSONObject jsonObject) {
        log.info("haofu callback jsonObject " + jsonObject);
        String orderId = jsonObject.getString("out_trade_no");
        String sign = jsonObject.getString("sign");
        String status = jsonObject.getString("status");
        log.info(String.format("haofu callback orderId=%s,sign=%s, status=%s", orderId, sign, status));

        if ("1".equals(status)) {
            if (!StringUtils.isEmpty(orderId)) {

                try {

                    if (!lock(orderId)) {
                        log.error("haofu callback is lock");
                        return "error";
                    }

                    PlatMerOrder order = platMerOrderService.getByOrderId(orderId);
                    if (StringUtils.equals(order.getStat(), "2")) {
                        log.info("haofu callback order success");
                        return "success";
                    }

                    PlatMer byMerIdCache = platMerService.getByMerIdCache(order.getMerId());
                    if (byMerIdCache == null) {
                        log.info("haofu callback plat mer is empty not fund");
                        return "plat mer is empty not fund";
                    }

                    jsonObject.remove("sign");
                    SortedMap sortedMap = new TreeMap();
                    for (String key : jsonObject.keySet()) {
                        sortedMap.put(key, jsonObject.getString(key));
                    }
                    String s = convertUrlNotEmpty(sortedMap, "&", "=") + "&" + byMerIdCache.getPrivateKey();
                    String md5Str = SecureUtil.md5(s).toLowerCase();

                    log.info("haofu s " + s);
                    log.info("haofu md5(s) " + md5Str);

                    if (md5Str.equals(sign)) {

                        if (order.getAmount().doubleValue() == (jsonObject.getDouble("amount_str"))) {

                            int b = platMerOrderService.success(order);

                            if (b > 0) {
                                log.info("haofu launch success");

                                report(order);
                                log.info("haofu success");
                                return "success";
                            } else {
                                log.error("haofu callback error");
                                return "error";
                            }

                        } else {
                            log.error("haofu callback amount is error");
                            return "amount is error";
                        }

                    } else {
                        log.error("haofu sign error");
                        return "sign error";
                    }

                } catch (RuntimeException ex) {
                    log.error("haofu notify EpayException", ex);
                    return "error" + ex.getMessage();
                } catch (Exception ex) {
                    log.error("haofu callback notify Exception", ex);
                    return "system ex ";
                } finally {
                    unlock(orderId);
                }
            } else {
                log.error("haofu callback plat order is error" + jsonObject.toJSONString());
                return "plat order status is error";
            }
        } else {
            log.error("haofu status is error" + jsonObject.toJSONString());
            return "plat order status is error";
        }
    }

    public String huanqiuUrl(JSONObject jsonObject) {
        log.info("huanqiu callback jsonObject " + jsonObject);
        String orderId = jsonObject.getString("outTradeNo");
        String sign = jsonObject.getString("sign");
        boolean status = jsonObject.getBoolean("success");
        log.info(String.format("huanqiu callback orderId=%s,sign=%s, status=%s", orderId, sign, status));

        if (status) {
            if (!StringUtils.isEmpty(orderId)) {

                try {

                    if (!lock(orderId)) {
                        log.error("huanqiu callback is lock");
                        return "error";
                    }

                    PlatMerOrder order = platMerOrderService.getByOrderId(orderId);
                    if (StringUtils.equals(order.getStat(), "2")) {
                        log.info("huanqiu callback order success");
                        return "success";
                    }

                    PlatMer byMerIdCache = platMerService.getByMerIdCache(order.getMerId());
                    if (byMerIdCache == null) {
                        log.info("huanqiu callback plat mer is empty not fund");
                        return "plat mer is empty not fund";
                    }

                    Map<String, String> map = new TreeMap<>();
                    map.put("merchantNo", jsonObject.getString("merchantNo"));
                    map.put("no", jsonObject.getString("no"));
                    map.put("nonce", jsonObject.getString("nonce"));
                    map.put("timestamp", jsonObject.getString("timestamp"));

                    String s = convertUrl(map, "&", "=") + "&key=" + byMerIdCache.getPrivateKey();
                    String md5Str = SecureUtil.md5(s);

                    log.info("huanqiu s " + s);
                    log.info("huanqiu md5(s) " + md5Str);

                    if (md5Str.toUpperCase().equals(sign)) {

                        if (order.getAmount().doubleValue() == (jsonObject.getDouble("money") / 100)) {

                            int b = platMerOrderService.success(order);

                            if (b > 0) {

                                report(order);
                                log.info("huanqiu success");
                                return "success";
                            } else {
                                log.error("huanqiu callback error");
                                return "error";
                            }

                        } else {
                            log.error("huanqiu callback amount is error");
                            return "amount is error";
                        }

                    } else {
                        log.error("huanqiu sign error");
                        return "sign error";
                    }

                } catch (RuntimeException ex) {
                    log.error("huanqiu notify EpayException", ex);
                    return "error" + ex.getMessage();
                } catch (Exception ex) {
                    log.error("huanqiu callback notify Exception", ex);
                    return "system ex ";
                } finally {
                    unlock(orderId);
                }
            } else {
                log.error("huanqiu callback plat order is error" + jsonObject.toJSONString());
                return "plat order status is error";
            }
        } else {
            log.error("huanqiu status is error" + jsonObject.toJSONString());
            return "plat order status is error";
        }
    }

    public String shengrongUrl(JSONObject jsonObject) {
        log.info("shengrong callback jsonObject " + jsonObject);
        String orderId = jsonObject.getString("out_order_id");
        String sign = jsonObject.getString("sign");
        String status = jsonObject.getString("status");
        log.info("shengrong callback orderid={},sign={},status={}", orderId, sign, status);

        if ("success".equals(status)) {
            if (!StringUtils.isEmpty(orderId)) {

                try {

                    if (!lock(orderId)) {
                        log.error("shengrong callback is lock");
                        return "error";
                    }

                    PlatMerOrder order = platMerOrderService.getByOrderId(orderId);
                    if (StringUtils.equals(order.getStat(), "2")) {
                        log.info("shengrong callback order success");
                        return "success";
                    }

                    PlatMer byMerIdCache = platMerService.getByMerIdCache(order.getMerId());
                    if (byMerIdCache == null) {
                        log.info("shengrong callback plat mer is empty not fund");
                        return "plat mer is empty not fund";
                    }

                    String s = SecureUtil.md5(SecureUtil.md5(jsonObject.getString("out_order_id") + jsonObject.getString("price") + jsonObject.getString("type") + jsonObject.getString("paytime") +
                            jsonObject.getString("extend")) + byMerIdCache.getPrivateKey());

                    log.info("shengrong s " + s);

                    if (s.equals(sign)) {

                        if (order.getAmount().doubleValue() == (jsonObject.getDouble("price"))) {

                            int b = platMerOrderService.success(order);

                            if (b > 0) {

                                report(order);
                                log.info("shengrong success");
                                return "success";
                            } else {
                                log.error("shengrong callback error");
                                return "error";
                            }

                        } else {
                            log.error("shengrong callback amount is error");
                            return "amount is error";
                        }

                    } else {
                        log.error("shengrong sign error");
                        return "sign error";
                    }

                } catch (RuntimeException ex) {
                    log.error("shengrong notify EpayException", ex);
                    return "error" + ex.getMessage();
                } catch (Exception ex) {
                    log.error("shengrong callback notify Exception", ex);
                    return "system ex ";
                } finally {
                    unlock(orderId);
                }
            } else {
                log.error("shengrong callback plat order is error" + jsonObject.toJSONString());
                return "plat order status is error";
            }
        } else {
            log.error("shengrong status is error" + jsonObject.toJSONString());
            return "plat order status is error";
        }
    }

    public String liandaUrl(JSONObject jsonObject) {
        return binli(jsonObject);
    }

    public String wanmeiUrl(JSONObject jsonObject) {
        log.info("wanmei callback jsonObject " + jsonObject);
        String orderId = jsonObject.getString("ACCOUNTINFO");
        String sign = jsonObject.getString("SIGN");
        String status = jsonObject.getString("status");
        log.info("wanmei callback orderid={},sign={},status={}", orderId, sign, status);

//        if ("success".equals(status)) {
        if (!StringUtils.isEmpty(orderId)) {

            try {

                if (!lock(orderId)) {
                    log.error("wanmei callback is lock");
                    return "error";
                }

                PlatMerOrder order = platMerOrderService.getByOrderId(orderId);
                if (StringUtils.equals(order.getStat(), "2")) {
                    log.info("wanmei callback order success");
                    return "success";
                }

                PlatMer byMerIdCache = platMerService.getByMerIdCache(order.getMerId());
                if (byMerIdCache == null) {
                    log.info("wanmei callback plat mer is empty not fund");
                    return "plat mer is empty not fund";
                }

                String s = jsonObject.getString("ACCOUNTINFO") + jsonObject.getString("ADDACCOUNTMONEY") +
                        "mp.perfect2pay.com" + jsonObject.getString("CLOUDID");
                log.info("s {}", s);

                String md5One = SecureUtil.md5(s);
                log.info("md5One {}", md5One);

                String md5Two = SecureUtil.md5(md5One + byMerIdCache.getPrivateKey());
                log.info("md5Two {}", md5Two);

                String subSign = md5Two.substring(8, 24);

                log.info("wanmei subSign " + subSign);

                if (subSign.equals(sign)) {

                    if (order.getAmount().doubleValue() == (jsonObject.getDouble("ADDACCOUNTMONEY"))) {

                        int b = platMerOrderService.success(order);

                        if (b > 0) {

                            report(order);
                            log.info("wanmei success");
                            return "success";
                        } else {
                            log.error("wanmei callback error");
                            return "error";
                        }

                    } else {
                        log.error("wanmei callback amount is error");
                        return "amount is error";
                    }

                } else {
                    log.error("wanmei sign error");
                    return "sign error";
                }

            } catch (RuntimeException ex) {
                log.error("wanmei notify EpayException", ex);
                return "error" + ex.getMessage();
            } catch (Exception ex) {
                log.error("wanmei callback notify Exception", ex);
                return "system ex ";
            } finally {
                unlock(orderId);
            }
        } else {
            log.error("wanmei callback plat order is error" + jsonObject.toJSONString());
            return "plat order status is error";
        }
//        } else {
//            log.error("wanmei status is error" + jsonObject.toJSONString());
//            return "plat order status is error";
//        }
    }

    public String jiuxuan(JSONObject jsonObject) {
        log.info("jsonObject {}", jsonObject);

        String merchOrder = jsonObject.getString("out_trade_no");
        String sign = jsonObject.getString("sign");

        jsonObject.remove("sign");
        SortedMap sortedMap = new TreeMap();
        for (String key : jsonObject.keySet()) {
            sortedMap.put(key, jsonObject.getString(key));
        }
//        if (!returncode.equals("1")) {
//            log.error("plat order is error" + jsonObject.toJSONString());
//            return "plat order is error";
//        }
        if (StringUtils.isEmpty(merchOrder)) {
            log.error("plat order id is empty" + merchOrder);
            return "plat order id is empty";
        }
        try {
            if (!lock(merchOrder)) {
                return "error";
            }
            PlatMerOrder byOrderId = platMerOrderService.getByOrderId(merchOrder);
            if (StringUtils.equals(byOrderId.getStat(), "2")) {
                return "SUCCESS";
            }
            PlatMer byMerIdCache = platMerService.getByMerIdCache(byOrderId.getMerId());
            if (byMerIdCache == null) {
                return "plat mer is empty not fund";
            }

            //拼接参数
            String plaintext = convertUrl(sortedMap, "&", "=") + "&key=" + byMerIdCache.getPrivateKey();
            ;

            log.info("s {}", plaintext);

            // 加签 MD5工具类使用通用的就行
            String s = SecureUtil.md5(plaintext).toUpperCase();

            log.info("sign {}", s);

            if (!s.equals(sign)) {
                return "sign error";
            }

            if (byOrderId.getAmount().doubleValue() != jsonObject.getDouble("total_fee")) {
                return "amount is  error";
            }
            int b = platMerOrderService.success(byOrderId);
            if (b > 0) {
                report(byOrderId);
                log.info("OK");
                return "SUCCESS";
            }
            return "error";

        } catch (RuntimeException ex) {
            log.error("notify EpayException", ex);
            return "error" + ex.getMessage();
        } catch (Exception ex) {
            log.error("notify Exception", ex);
            return "system ex ";
        } finally {
            unlock(merchOrder);
        }

    }

    public String shejiao(JSONObject jsonObject) {

        String merchOrder = jsonObject.getString("orderNo");

        String status = jsonObject.getString("state");
        String sign = jsonObject.getString("sign");

        //message
        jsonObject.remove("sign");

        if (!status.equals("1")) {
            log.error("plat order is error" + jsonObject.toJSONString());
            return "plat order status is error";
        }


        if (StringUtils.isEmpty(merchOrder)) {

            log.error("plat order id is empty" + merchOrder);
            return "plat order id is empty";
        }

        try {
            if (!lock(merchOrder)) {
                return "error";
            }


            PlatMerOrder byOrderId = platMerOrderService.getByOrderId(merchOrder);

            if (StringUtils.equals(byOrderId.getStat(), "2")) {
                return "SUCCESS";
            }

            PlatMer byMerIdCache = platMerService.getByMerIdCache(byOrderId.getMerId());

            if (byMerIdCache == null) {
                return "plat mer is empty not fund";
            }


            String s = jsonObject.getString("state") + byMerIdCache.getMerKey() + jsonObject.getString("orderNo") + jsonObject.getString("amount") + byMerIdCache.getPrivateKey();
            log.error(" sign url error {}", s);
//            String sign = SecureUtil.md5(s +"&"+ byMerIdCache.getPrivateKey()).toLowerCase();
            log.error(" sign url error {}", s);
            if (!SecureUtil.md5(s).toUpperCase().equals(sign)) {
                return "sign error";
            }


            if (byOrderId.getAmount().doubleValue() != jsonObject.getDouble("amount")) {
                return "amount is  error";
            }

            int b = platMerOrderService.success(byOrderId);
            if (b > 0) {


                report(byOrderId);

                return "SUCCESS";
            }
            return "error";

        } catch (RuntimeException ex) {
            log.error("notify EpayException", ex);
            return "error" + ex.getMessage();
        } catch (Exception ex) {
            log.error("notify Exception", ex);
            return "system ex ";
        } finally {
            unlock(merchOrder);
        }

    }

    public String juheUrl(JSONObject jsonObject) {
        return qfb(jsonObject);
    }

    public String dxerUrl(JSONObject jsonObject) {
        log.info("dxer callback jsonObject " + jsonObject);
        String orderId = jsonObject.getString("out_trade_no");
        String sign = jsonObject.getString("sign");
        String status = jsonObject.getString("status");
        log.info("dxer callback orderid={},sign={},status={}", orderId, sign, status);

        if ("success".equals(status)) {
            if (!StringUtils.isEmpty(orderId)) {

                try {

                    if (!lock(orderId)) {
                        log.error("dxer callback is lock");
                        return "error";
                    }

                    PlatMerOrder order = platMerOrderService.getByOrderId(orderId);
                    if (StringUtils.equals(order.getStat(), "2")) {
                        log.info("dxer callback order success");
                        return "success";
                    }

                    PlatMer byMerIdCache = platMerService.getByMerIdCache(order.getMerId());
                    if (byMerIdCache == null) {
                        log.info("dxer callback plat mer is empty not fund");
                        return "plat mer is empty not fund";
                    }

                    jsonObject.remove("sign");
                    SortedMap sortedMap = new TreeMap();
                    for (String key : jsonObject.keySet()) {
                        sortedMap.put(key, jsonObject.getString(key));
                    }
                    String s = convertUrlNotEmpty(sortedMap, "&", "=") + byMerIdCache.getPrivateKey();
                    String md5Str = SecureUtil.md5(s).toUpperCase();

                    log.info("s {}", s);
                    log.info("dxer {}", md5Str);

                    if (md5Str.equals(sign)) {
                        double min = order.getAmount().subtract(new BigDecimal(1)).doubleValue();
                        double max = order.getAmount().add(new BigDecimal(1)).doubleValue();

                        Double pay_money = jsonObject.getDouble("pay_amount");
                        /**
                         * 浮动金额
                         */
                        if ((pay_money.doubleValue() >= min && pay_money.doubleValue() <= max)) {

                            int b = platMerOrderService.success(order);

                            if (b > 0) {

                                report(order);
                                log.info("dxer success");
                                return "success";
                            } else {
                                log.error("dxer callback error");
                                return "error";
                            }

                        } else {
                            log.error("dxer callback amount is error");
                            return "amount is error";
                        }

                    } else {
                        log.error("dxer sign error");
                        return "sign error";
                    }

                } catch (RuntimeException ex) {
                    log.error("dxer notify EpayException", ex);
                    return "error" + ex.getMessage();
                } catch (Exception ex) {
                    log.error("dxer callback notify Exception", ex);
                    return "system ex ";
                } finally {
                    unlock(orderId);
                }
            } else {
                log.error("dxer callback plat order is error" + jsonObject.toJSONString());
                return "plat order status is error";
            }
        } else {
            log.error("dxer status is error" + jsonObject.toJSONString());
            return "plat order status is error";
        }
    }

    public String seboUrl(JSONObject jsonObject) {
        log.info("dxer callback jsonObject " + jsonObject);
        String orderId = jsonObject.getString("ordersn");
        String sign = jsonObject.getString("sign");
        String status = jsonObject.getString("status");
        log.info("dxer callback orderid={},sign={},status={}", orderId, sign, status);

//        if ("success".equals(status)) {
        if (!StringUtils.isEmpty(orderId)) {

            try {

                if (!lock(orderId)) {
                    log.error("dxer callback is lock");
                    return "error";
                }

                PlatMerOrder order = platMerOrderService.getByOrderId(orderId);
                if (StringUtils.equals(order.getStat(), "2")) {
                    log.info("dxer callback order success");
                    return "success";
                }

                PlatMer byMerIdCache = platMerService.getByMerIdCache(order.getMerId());
                if (byMerIdCache == null) {
                    log.info("dxer callback plat mer is empty not fund");
                    return "plat mer is empty not fund";
                }

                jsonObject.remove("sign");
                SortedMap sortedMap = new TreeMap();
                for (String key : jsonObject.keySet()) {
                    sortedMap.put(key, jsonObject.getString(key));
                }
                String s = convertUrlNotEmpty(sortedMap, "&", "=") + "&key=" + byMerIdCache.getPrivateKey();
                String md5Str = SecureUtil.md5(s);

                log.info("s {}", s);
                log.info("dxer {}", md5Str);

                if (md5Str.equals(sign)) {
                    double min = order.getAmount().subtract(new BigDecimal(1)).doubleValue();
                    double max = order.getAmount().add(new BigDecimal(1)).doubleValue();

                    Double pay_money = jsonObject.getDouble("pay_money");
                    /**
                     * 浮动金额
                     */
                    if ((pay_money.doubleValue() >= min && pay_money.doubleValue() <= max)) {


                        int b = platMerOrderService.success(order);

                        if (b > 0) {

                            report(order);
                            log.info("dxer success");
                            return "success";
                        } else {
                            log.error("dxer callback error");
                            return "error";
                        }

                    } else {
                        log.error("dxer callback amount is error");
                        return "amount is error";
                    }

                } else {
                    log.error("dxer sign error");
                    return "sign error";
                }

            } catch (RuntimeException ex) {
                log.error("dxer notify EpayException", ex);
                return "error" + ex.getMessage();
            } catch (Exception ex) {
                log.error("dxer callback notify Exception", ex);
                return "system ex ";
            } finally {
                unlock(orderId);
            }
        } else {
            log.error("dxer callback plat order is error" + jsonObject.toJSONString());
            return "plat order status is error";
        }
//        } else {
//            log.error("dxer status is error" + jsonObject.toJSONString());
//            return "plat order status is error";
//        }
    }

    public String haitun2Url(JSONObject jsonObject) {
        log.info("haitun2 callback jsonObject " + jsonObject);
        String orderId = jsonObject.getString("trade_order_no");
        String sign = jsonObject.getString("sign");
        String status = jsonObject.getString("status");
        log.info("haitun2 callback orderid={},sign={},status={}", orderId, sign, status);

//        if ("success".equals(status)) {
        if (!StringUtils.isEmpty(orderId)) {

            try {

                if (!lock(orderId)) {
                    log.error("haitun2 callback is lock");
                    return "error";
                }

                PlatMerOrder order = platMerOrderService.getByOrderId(orderId);
                if (StringUtils.equals(order.getStat(), "2")) {
                    log.info("haitun2 callback order success");
                    return "success";
                }

                PlatMer byMerIdCache = platMerService.getByMerIdCache(order.getMerId());
                if (byMerIdCache == null) {
                    log.info("haitun2 callback plat mer is empty not fund");
                    return "plat mer is empty not fund";
                }

                String s = jsonObject.getString("trade_order_no") + jsonObject.getString("serial_no") +
                        jsonObject.getString("payment_code") + jsonObject.getString("payment_amount") + jsonObject.getString("real_amount") +
                        byMerIdCache.getPrivateKey();
                String md5Str = SecureUtil.md5(s);

                log.info("haitun2 s  {}", s);
                log.info("haitun2 sre {}", md5Str);

                if (md5Str.equals(sign)) {

                    double min = order.getAmount().subtract(new BigDecimal(1)).doubleValue();
                    double max = order.getAmount().add(new BigDecimal(1)).doubleValue();

                    Double pay_money = jsonObject.getDouble("payment_amount");
                    /**
                     * 浮动金额
                     */
                    if ((pay_money.doubleValue() >= min && pay_money.doubleValue() <= max)) {

                        int b = platMerOrderService.success(order);

                        if (b > 0) {

                            report(order);
                            log.info("haitun2 success");
                            return "success";
                        } else {
                            log.error("haitun2 callback error");
                            return "error";
                        }

                    } else {
                        log.error("haitun2 callback amount is error");
                        return "amount is error";
                    }

                } else {
                    log.error("haitun2 sign error");
                    return "sign error";
                }

            } catch (RuntimeException ex) {
                log.error("haitun2 notify EpayException", ex);
                return "error" + ex.getMessage();
            } catch (Exception ex) {
                log.error("haitun2 callback notify Exception", ex);
                return "system ex ";
            } finally {
                unlock(orderId);
            }
        } else {
            log.error("haitun2 callback plat order is error" + jsonObject.toJSONString());
            return "plat order status is error";
        }
//        } else {
//            log.error("dxer status is error" + jsonObject.toJSONString());
//            return "plat order status is error";
//        }
    }

    public String qianjinfuUrl(JSONObject jsonObject) {
        log.info("qianjinfu callback jsonObject " + jsonObject);
        String orderId = jsonObject.getString("tradeNo");
        String sign = jsonObject.getString("sign");
        String status = jsonObject.getString("returnCode");
        log.info("qianjinfu callback orderid={},sign={},status={}", orderId, sign, status);

        if ("00".equals(status)) {
            if (!StringUtils.isEmpty(orderId)) {

                try {

                    if (!lock(orderId)) {
                        log.error("qianjinfu callback is lock");
                        return "error";
                    }

                    PlatMerOrder order = platMerOrderService.getByOrderId(orderId);
                    if (StringUtils.equals(order.getStat(), "2")) {
                        log.info("qianjinfu callback order success");
                        return "success";
                    }

                    PlatMer byMerIdCache = platMerService.getByMerIdCache(order.getMerId());
                    if (byMerIdCache == null) {
                        log.info("qianjinfu callback plat mer is empty not fund");
                        return "plat mer is empty not fund";
                    }

                    jsonObject.remove("sign");
                    SortedMap sortedMap = new TreeMap();
                    for (String key : jsonObject.keySet()) {
                        sortedMap.put(key, jsonObject.getString(key));
                    }
                    String s = convertUrlNotEmpty(sortedMap, "&", "=") + "&key=" + byMerIdCache.getPrivateKey();
                    String md5Str = SecureUtil.md5(s);

                    log.info("qianjinfu s  {}", s);
                    log.info("qianjinfu sre {}", md5Str);

                    if (md5Str.equals(sign)) {

                        Double pay_money = jsonObject.getBigDecimal("amount").doubleValue();
                        /**
                         * 浮动金额
                         */
                        if (order.getAmount().doubleValue() == pay_money.doubleValue()) {

                            int b = platMerOrderService.success(order);

                            if (b > 0) {

                                report(order);
                                log.info("qianjinfu success");
                                return "success";
                            } else {
                                log.error("qianjinfu callback error");
                                return "error";
                            }

                        } else {
                            log.error("qianjinfu callback amount is error order.getAmount(){} pay_money{}", order.getAmount(), pay_money);
                            return "amount is error";
                        }

                    } else {
                        log.error("qianjinfu sign error");
                        return "sign error";
                    }

                } catch (RuntimeException ex) {
                    log.error("qianjinfu notify EpayException", ex);
                    return "error" + ex.getMessage();
                } catch (Exception ex) {
                    log.error("qianjinfu callback notify Exception", ex);
                    return "system ex ";
                } finally {
                    unlock(orderId);
                }
            } else {
                log.error("qianjinfu callback plat order is error" + jsonObject.toJSONString());
                return "plat order status is error";
            }
        } else {
            log.error("qianjinfu status is error" + jsonObject.toJSONString());
            return "plat order status is error";
        }
    }

    public String suibianUrl(JSONObject jsonObject) {
        log.info("suibian callback jsonObject " + jsonObject);
        String orderId = jsonObject.getString("tenant_order_id");
        String sign = jsonObject.getString("sign");
        String status = jsonObject.getString("code");
        log.info("suibian callback orderid={},sign={},status={}", orderId, sign, status);

        if ("0".equals(status)) {
            if (!StringUtils.isEmpty(orderId)) {

                try {

                    if (!lock(orderId)) {
                        log.error("suibian callback is lock");
                        return "error";
                    }

                    PlatMerOrder order = platMerOrderService.getByOrderId(orderId);
                    if (StringUtils.equals(order.getStat(), "2")) {
                        log.info("suibian callback order success");
                        return "success";
                    }

                    PlatMer byMerIdCache = platMerService.getByMerIdCache(order.getMerId());
                    if (byMerIdCache == null) {
                        log.info("suibian callback plat mer is empty not fund");
                        return "plat mer is empty not fund";
                    }

                    jsonObject.remove("sign");
                    SortedMap sortedMap = new TreeMap();
                    for (String key : jsonObject.keySet()) {
                        sortedMap.put(key, jsonObject.getString(key));
                    }
                    String s = convertUrlIsEmpty(sortedMap, "&", "=") + "&secret=" + byMerIdCache.getPrivateKey();
                    String md5Str = SecureUtil.md5(s).toUpperCase();

                    log.info("suibian s  {}", s);
                    log.info("suibian sre {}", md5Str);

                    if (md5Str.equals(sign)) {

                        Double pay_money = jsonObject.getBigDecimal("amount").doubleValue();
                        /**
                         * 浮动金额
                         */
                        if (order.getAmount().doubleValue() == new BigDecimal(pay_money.doubleValue()).divide(new BigDecimal(100)).doubleValue()) {

                            int b = platMerOrderService.success(order);

                            if (b > 0) {

                                report(order);
                                log.info("suibian success");
                                return "success";
                            } else {
                                log.error("suibian callback error");
                                return "error";
                            }

                        } else {
                            log.error("suibian callback amount is error order.getAmount(){} pay_money{}", order.getAmount(), pay_money);
                            return "amount is error";
                        }

                    } else {
                        log.error("suibian sign error");
                        return "sign error";
                    }

                } catch (RuntimeException ex) {
                    log.error("suibian notify EpayException", ex);
                    return "error" + ex.getMessage();
                } catch (Exception ex) {
                    log.error("suibian callback notify Exception", ex);
                    return "system ex ";
                } finally {
                    unlock(orderId);
                }
            } else {
                log.error("suibian callback plat order is error" + jsonObject.toJSONString());
                return "plat order status is error";
            }
        } else {
            log.error("suibian status is error" + jsonObject.toJSONString());
            return "plat order status is error";
        }
    }

    public String wuyueUrl(JSONObject jsonObject) {
        log.info("wuyue callback jsonObject " + jsonObject);
        String orderId = jsonObject.getString("out_order_no");
        String sign = jsonObject.getString("sign");
        String status = jsonObject.getString("code");
        log.info("wuyue callback orderid={},sign={},status={}", orderId, sign, status);

        if ("1".equals(status)) {
            if (!StringUtils.isEmpty(orderId)) {

                try {

                    if (!lock(orderId)) {
                        log.error("wuyue callback is lock");
                        return "error";
                    }

                    PlatMerOrder order = platMerOrderService.getByOrderId(orderId);
                    if (StringUtils.equals(order.getStat(), "2")) {
                        log.info("wuyue callback order success");
                        return "success";
                    }

                    PlatMer byMerIdCache = platMerService.getByMerIdCache(order.getMerId());
                    if (byMerIdCache == null) {
                        log.info("wuyue callback plat mer is empty not fund");
                        return "plat mer is empty not fund";
                    }

                    String s = jsonObject.getString("order_no") + jsonObject.getString("merchant_no") + jsonObject.getString("out_order_no") +
                            jsonObject.getString("amount") + jsonObject.getString("pay_type") + jsonObject.getString("code") +
                            byMerIdCache.getPrivateKey();

                    String md5Str = SecureUtil.md5(s);

                    log.info("wuyue s  {}", s);
                    log.info("wuyue sre {}", md5Str);

                    if (md5Str.equals(sign)) {

                        Double pay_money = jsonObject.getBigDecimal("amount").doubleValue();
                        /**
                         * 浮动金额
                         */
                        if (order.getAmount().doubleValue() == pay_money.doubleValue()) {

                            int b = platMerOrderService.success(order);

                            if (b > 0) {

                                report(order);
                                log.info("wuyue success");
                                return "success";
                            } else {
                                log.error("wuyue callback error");
                                return "error";
                            }

                        } else {
                            log.error("wuyue callback amount is error order.getAmount(){} pay_money{}", order.getAmount(), pay_money);
                            return "amount is error";
                        }

                    } else {
                        log.error("wuyue sign error");
                        return "sign error";
                    }

                } catch (RuntimeException ex) {
                    log.error("wuyue notify EpayException", ex);
                    return "error" + ex.getMessage();
                } catch (Exception ex) {
                    log.error("wuyue callback notify Exception", ex);
                    return "system ex ";
                } finally {
                    unlock(orderId);
                }
            } else {
                log.error("wuyue callback plat order is error" + jsonObject.toJSONString());
                return "plat order status is error";
            }
        } else {
            log.error("wuyue status is error" + jsonObject.toJSONString());
            return "plat order status is error";
        }
    }

    public String kaerUrl(JSONObject jsonObject) {
        log.info("kaer callback jsonObject " + jsonObject);
        String orderId = jsonObject.getString("orderNo");
        String sign = jsonObject.getString("sign");
        String status = jsonObject.getString("state");
        log.info("kaer callback orderid={},sign={},status={}", orderId, sign, status);

        if ("1".equals(status)) {
            if (!StringUtils.isEmpty(orderId)) {

                try {

                    if (!lock(orderId)) {
                        log.error("kaer callback is lock");
                        return "error";
                    }

                    PlatMerOrder order = platMerOrderService.getByOrderId(orderId);
                    if (StringUtils.equals(order.getStat(), "2")) {
                        log.info("kaer callback order success");
                        return "success";
                    }

                    PlatMer byMerIdCache = platMerService.getByMerIdCache(order.getMerId());
                    if (byMerIdCache == null) {
                        log.info("kaer callback plat mer is empty not fund");
                        return "plat mer is empty not fund";
                    }

                    String s = jsonObject.getString("state") + jsonObject.getString("merchantNum") + jsonObject.getString("orderNo") +
                            jsonObject.getString("amount") + byMerIdCache.getPrivateKey();
                    String md5Str = SecureUtil.md5(s);

                    log.info("kaer s  {}", s);
                    log.info("kaer sre {}", md5Str);

                    if (md5Str.equals(sign)) {

                        Double pay_money = jsonObject.getBigDecimal("amount").doubleValue();
                        /**
                         * 浮动金额
                         */
                        if (order.getAmount().doubleValue() == pay_money.doubleValue()) {

                            int b = platMerOrderService.success(order);

                            if (b > 0) {

                                report(order);
                                log.info("kaer success");
                                return "success";
                            } else {
                                log.error("kaer callback error");
                                return "error";
                            }

                        } else {
                            log.error("kaer callback amount is error order.getAmount(){} pay_money{}", order.getAmount(), pay_money);
                            return "amount is error";
                        }

                    } else {
                        log.error("kaer sign error");
                        return "sign error";
                    }

                } catch (RuntimeException ex) {
                    log.error("kaer notify EpayException", ex);
                    return "error" + ex.getMessage();
                } catch (Exception ex) {
                    log.error("kaer callback notify Exception", ex);
                    return "system ex ";
                } finally {
                    unlock(orderId);
                }
            } else {
                log.error("kaer callback plat order is error" + jsonObject.toJSONString());
                return "plat order status is error";
            }
        } else {
            log.error("kaer status is error" + jsonObject.toJSONString());
            return "plat order status is error";
        }
    }

    public String payOneOkUrl(JSONObject jsonObject) {
        log.info("kaer callback jsonObject " + jsonObject);
        String orderId = jsonObject.getString("mcOrderId");
        String sign = jsonObject.getString("sign");
        String status = jsonObject.getString("orderStatus");
        log.info("kaer callback orderid={},sign={},status={}", orderId, sign, status);

        if ("paid".equals(status)) {
            if (!StringUtils.isEmpty(orderId)) {

                try {

                    if (!lock(orderId)) {
                        log.error("kaer callback is lock");
                        return "error";
                    }

                    PlatMerOrder order = platMerOrderService.getByOrderId(orderId);
                    if (StringUtils.equals(order.getStat(), "2")) {
                        log.info("kaer callback order success");
                        return "success";
                    }

                    PlatMer byMerIdCache = platMerService.getByMerIdCache(order.getMerId());
                    if (byMerIdCache == null) {
                        log.info("kaer callback plat mer is empty not fund");
                        return "plat mer is empty not fund";
                    }

                    jsonObject.remove("sign");
                    SortedMap sortedMap = new TreeMap();
                    for (String key : jsonObject.keySet()) {
                        sortedMap.put(key, jsonObject.getString(key));
                    }
                    String s = convertUrlIsEmpty(sortedMap, "&", "=") + byMerIdCache.getPrivateKey();
                    String md5Str = SecureUtil.md5(s).toUpperCase();

                    if (md5Str.equals(sign)) {

                        Double pay_money = jsonObject.getBigDecimal("orderMoney").doubleValue();
                        /**
                         * 浮动金额
                         */
                        if (order.getAmount().doubleValue() == pay_money.doubleValue()) {

                            int b = platMerOrderService.success(order);

                            if (b > 0) {

                                report(order);
                                log.info("kaer success");
                                return "success";
                            } else {
                                log.error("kaer callback error");
                                return "error";
                            }

                        } else {
                            log.error("kaer callback amount is error order.getAmount(){} pay_money{}", order.getAmount(), pay_money);
                            return "amount is error";
                        }

                    } else {
                        log.error("kaer sign error");
                        return "sign error";
                    }

                } catch (RuntimeException ex) {
                    log.error("kaer notify EpayException", ex);
                    return "error" + ex.getMessage();
                } catch (Exception ex) {
                    log.error("kaer callback notify Exception", ex);
                    return "system ex ";
                } finally {
                    unlock(orderId);
                }
            } else {
                log.error("kaer callback plat order is error" + jsonObject.toJSONString());
                return "plat order status is error";
            }
        } else {
            log.error("kaer status is error" + jsonObject.toJSONString());
            return "plat order status is error";
        }
    }


    public String OTCXUrl(JSONObject jsonObject) {
        log.info("OTCX callback jsonObject " + jsonObject);
        String orderId = jsonObject.getString("orderRemark");
        String sign = jsonObject.getString("hmac");
        String status = jsonObject.getString("state");
        log.info("OTCX callback orderid={},sign={},status={}", orderId, sign, status);

        if ("3".equals(status)) {
            if (!StringUtils.isEmpty(orderId)) {

                try {

                    if (!lock(orderId)) {
                        log.error("OTCX callback is lock");
                        return "error";
                    }

                    PlatMerOrder order = platMerOrderService.getByOrderId(orderId);
                    if (StringUtils.equals(order.getStat(), "2")) {
                        log.info("OTCX callback order success");
                        return "success";
                    }

                    PlatMer byMerIdCache = platMerService.getByMerIdCache(order.getMerId());
                    if (byMerIdCache == null) {
                        log.info("OTCX callback plat mer is empty not fund");
                        return "plat mer is empty not fund";
                    }

                    String s = jsonObject.getString("id") + byMerIdCache.getPrivateKey() + jsonObject.getString("orderRemark") + jsonObject.getString("state")
                            + jsonObject.getString("type") + jsonObject.getDate("updateTime").getTime() + jsonObject.getString("userId");
                    String md5Str = SecureUtil.md5(s).toUpperCase();

                    if (md5Str.equals(sign)) {

                        int b = platMerOrderService.success(order);

                        if (b > 0) {

                            report(order);
                            log.info("OTCX success");
                            return "success";
                        } else {
                            log.error("OTCX callback error");
                            return "error";
                        }

                    } else {
                        log.error("OTCX sign error");
                        return "sign error";
                    }

                } catch (RuntimeException ex) {
                    log.error("OTCX notify EpayException", ex);
                    return "error" + ex.getMessage();
                } catch (Exception ex) {
                    log.error("OTCX callback notify Exception", ex);
                    return "system ex ";
                } finally {
                    unlock(orderId);
                }
            } else {
                log.error("OTCX callback plat order is error" + jsonObject.toJSONString());
                return "plat order status is error";
            }
        } else {
            log.error("OTCX status is error" + jsonObject.toJSONString());
            return "plat order status is error";
        }
    }

    public String dingshunUrl(JSONObject jsonObject) {
        log.info("dingshun callback jsonObject " + jsonObject);
        String orderId = jsonObject.getString("out_trade_id");
        String sign = jsonObject.getString("sign");
        String status = jsonObject.getString("status");
        log.info("dingshun callback orderid={},sign={},status={}", orderId, sign, status);

        if ("2".equals(status)) {
            if (!StringUtils.isEmpty(orderId)) {

                try {

                    if (!lock(orderId)) {
                        log.error("dingshun callback is lock");
                        return "error";
                    }

                    PlatMerOrder order = platMerOrderService.getByOrderId(orderId);
                    if (StringUtils.equals(order.getStat(), "2")) {
                        log.info("dingshun callback order success");
                        return "success";
                    }

                    PlatMer byMerIdCache = platMerService.getByMerIdCache(order.getMerId());
                    if (byMerIdCache == null) {
                        log.info("dingshun callback plat mer is empty not fund");
                        return "plat mer is empty not fund";
                    }

                    jsonObject.remove("sign");
                    SortedMap sortedMap = new TreeMap();
                    for (String key : jsonObject.keySet()) {
                        sortedMap.put(key, jsonObject.getString(key));
                    }
                    String s = convertUrl(sortedMap, "&", "=") + "&key=" + byMerIdCache.getPrivateKey();
                    String md5Str = SecureUtil.md5(s).toLowerCase();

                    if (md5Str.equals(sign)) {

                        Double pay_money = jsonObject.getBigDecimal("amount").doubleValue();
                        /**
                         * 浮动金额
                         */
                        if (order.getAmount().doubleValue() == pay_money.doubleValue()) {

                            int b = platMerOrderService.success(order);

                            if (b > 0) {

                                report(order);
                                log.info("dingshun success");
                                return "success";
                            } else {
                                log.error("dingshun callback error");
                                return "error";
                            }

                        } else {
                            log.error("dingshun callback amount is error order.getAmount(){} pay_money{}", order.getAmount(), pay_money);
                            return "amount is error";
                        }

                    } else {
                        log.error("dingshun sign error");
                        return "sign error";
                    }

                } catch (RuntimeException ex) {
                    log.error("dingshun notify EpayException", ex);
                    return "error" + ex.getMessage();
                } catch (Exception ex) {
                    log.error("dingshun callback notify Exception", ex);
                    return "system ex ";
                } finally {
                    unlock(orderId);
                }
            } else {
                log.error("dingshun callback plat order is error" + jsonObject.toJSONString());
                return "plat order status is error";
            }
        } else {
            log.error("dingshun status is error" + jsonObject.toJSONString());
            return "plat order status is error";
        }
    }

    public String sljUrl(JSONObject jsonObject) {
        log.info("slj callback jsonObject " + jsonObject);
        String orderId = jsonObject.getString("orderid");
        String sign = jsonObject.getString("sign");
        String status = jsonObject.getString("returncode");
        log.info("slj callback orderid={},sign={},status={}", orderId, sign, status);

        if ("00".equals(status)) {
            if (!StringUtils.isEmpty(orderId)) {

                try {

                    if (!lock(orderId)) {
                        log.error("slj callback is lock");
                        return "error";
                    }

                    PlatMerOrder order = platMerOrderService.getByOrderId(orderId);
                    if (StringUtils.equals(order.getStat(), "2")) {
                        log.info("slj callback order success");
                        return "success";
                    }

                    PlatMer byMerIdCache = platMerService.getByMerIdCache(order.getMerId());
                    if (byMerIdCache == null) {
                        log.info("slj callback plat mer is empty not fund");
                        return "plat mer is empty not fund";
                    }

                    jsonObject.remove("sign");
                    SortedMap sortedMap = new TreeMap();
                    for (String key : jsonObject.keySet()) {
                        sortedMap.put(key, jsonObject.getString(key));
                    }
                    String s = convertUrl(sortedMap, "&", "=") + "&key=" + byMerIdCache.getPrivateKey();
                    String md5Str = SecureUtil.md5(s).toUpperCase();

                    if (md5Str.equals(sign)) {

                        Double pay_money = jsonObject.getBigDecimal("amount").doubleValue();
                        /**
                         * 浮动金额
                         */
                        if (order.getAmount().doubleValue() == pay_money.doubleValue()) {

                            int b = platMerOrderService.success(order);

                            if (b > 0) {

                                report(order);
                                log.info("slj success");
                                return "OK";
                            } else {
                                log.error("slj callback error");
                                return "error";
                            }

                        } else {
                            log.error("slj callback amount is error order.getAmount(){} pay_money{}", order.getAmount(), pay_money);
                            return "amount is error";
                        }

                    } else {
                        log.error("slj sign error");
                        return "sign error";
                    }

                } catch (RuntimeException ex) {
                    log.error("slj notify EpayException", ex);
                    return "error" + ex.getMessage();
                } catch (Exception ex) {
                    log.error("slj callback notify Exception", ex);
                    return "system ex ";
                } finally {
                    unlock(orderId);
                }
            } else {
                log.error("slj callback plat order is error" + jsonObject.toJSONString());
                return "plat order status is error";
            }
        } else {
            log.error("slj status is error" + jsonObject.toJSONString());
            return "plat order status is error";
        }
    }

    public String hookUrl(JSONObject jsonObject) {
        return jinxinUrl(jsonObject);
    }

    public String yuanshengUrl(JSONObject jsonObject) {
        return sljUrl(jsonObject);
    }

    public String julianUrl(JSONObject jsonObject) {
        log.info("julian callback jsonObject " + jsonObject);
        String orderId = jsonObject.getString("merchOrderNum");
        String sign = jsonObject.getString("sign");
        String status = jsonObject.getString("payState");
        log.info("julian callback orderid={},sign={},status={}", orderId, sign, status);

        if ("SUCCESS".equals(status)) {
            if (!StringUtils.isEmpty(orderId)) {

                try {

                    if (!lock(orderId)) {
                        log.error("julian callback is lock");
                        return "error";
                    }

                    PlatMerOrder order = platMerOrderService.getByOrderId(orderId);
                    if (StringUtils.equals(order.getStat(), "2")) {
                        log.info("julian callback order success");
                        return "success";
                    }

                    PlatMer byMerIdCache = platMerService.getByMerIdCache(order.getMerId());
                    if (byMerIdCache == null) {
                        log.info("julian callback plat mer is empty not fund");
                        return "plat mer is empty not fund";
                    }

                    jsonObject.remove("sign");
                    jsonObject.remove("t");
                    SortedMap sortedMap = new TreeMap();
                    for (String key : jsonObject.keySet()) {
                        sortedMap.put(key, jsonObject.getString(key));
                    }
                    String s = convertUrl(sortedMap, "&", "=") + "&key=" + byMerIdCache.getPrivateKey();
                    String md5Str = SecureUtil.md5(s).toUpperCase();

                    if (md5Str.equals(sign)) {

                        Double pay_money = jsonObject.getBigDecimal("orderAmount").divide(new BigDecimal(100)).doubleValue();
                        /**
                         * 浮动金额
                         */
                        if (order.getAmount().doubleValue() == pay_money.doubleValue()) {

                            int b = platMerOrderService.success(order);

                            if (b > 0) {

                                report(order);
                                log.info("julian success");
                                return "success";
                            } else {
                                log.error("julian callback error");
                                return "error";
                            }

                        } else {
                            log.error("julian callback amount is error order.getAmount(){} pay_money{}", order.getAmount(), pay_money);
                            return "amount is error";
                        }

                    } else {
                        log.error("julian sign error");
                        return "sign error";
                    }

                } catch (RuntimeException ex) {
                    log.error("julian notify EpayException", ex);
                    return "error" + ex.getMessage();
                } catch (Exception ex) {
                    log.error("julian callback notify Exception", ex);
                    return "system ex ";
                } finally {
                    unlock(orderId);
                }
            } else {
                log.error("julian callback plat order is error" + jsonObject.toJSONString());
                return "plat order status is error";
            }
        } else {
            log.error("julian status is error" + jsonObject.toJSONString());
            return "plat order status is error";
        }
    }

    public String kubeiUrl(JSONObject jsonObject) {
        return sljUrl(jsonObject);
    }

    public String baichuanUrl(JSONObject jsonObject) {
        log.info("baichuan callback jsonObject " + jsonObject);
        String orderId = jsonObject.getString("out_order_id");
        String sign = jsonObject.getString("sign");
        String status = jsonObject.getString("notice");
        log.info("baichuan callback orderid={},sign={},status={}", orderId, sign, status);

        if ("1".equals(status)) {
            if (!StringUtils.isEmpty(orderId)) {

                try {

                    if (!lock(orderId)) {
                        log.error("baichuan callback is lock");
                        return "error";
                    }

                    PlatMerOrder order = platMerOrderService.getByOrderId(orderId);
                    if (StringUtils.equals(order.getStat(), "2")) {
                        log.info("baichuan callback order success");
                        return "success";
                    }

                    PlatMer byMerIdCache = platMerService.getByMerIdCache(order.getMerId());
                    if (byMerIdCache == null) {
                        log.info("baichuan callback plat mer is empty not fund");
                        return "plat mer is empty not fund";
                    }

                    jsonObject.remove("sign");
                    SortedMap sortedMap = new TreeMap();
                    for (String key : jsonObject.keySet()) {
                        sortedMap.put(key, jsonObject.getString(key));
                    }
                    String s = convertUrl(sortedMap, "&", "=") + "&key=" + byMerIdCache.getPrivateKey();
                    String md5Str = SecureUtil.md5(s).toUpperCase();

                    if (md5Str.equals(sign)) {

                        Double pay_money = jsonObject.getBigDecimal("money").doubleValue();
                        /**
                         * 浮动金额
                         */
                        if (order.getAmount().doubleValue() == pay_money.doubleValue()) {

                            int b = platMerOrderService.success(order);

                            if (b > 0) {

                                report(order);
                                log.info("baichuan success");
                                return "ok";
                            } else {
                                log.error("baichuan callback error");
                                return "error";
                            }

                        } else {
                            log.error("baichuan callback amount is error order.getAmount(){} pay_money{}", order.getAmount(), pay_money);
                            return "amount is error";
                        }

                    } else {
                        log.error("baichuan sign error");
                        return "sign error";
                    }

                } catch (RuntimeException ex) {
                    log.error("baichuan notify EpayException", ex);
                    return "error" + ex.getMessage();
                } catch (Exception ex) {
                    log.error("baichuan callback notify Exception", ex);
                    return "system ex ";
                } finally {
                    unlock(orderId);
                }
            } else {
                log.error("baichuan callback plat order is error" + jsonObject.toJSONString());
                return "plat order status is error";
            }
        } else {
            log.error("baichuan status is error" + jsonObject.toJSONString());
            return "plat order status is error";
        }
    }

    public String stormUrl(JSONObject jsonObject) {
        log.info("stormUrl callback jsonObject " + jsonObject);
        String orderId = jsonObject.getString("out_trade_no");
        String sign = jsonObject.getString("sign");
        String status = jsonObject.getString("notice");
        log.info("stormUrl callback orderid={},sign={},status={}", orderId, sign, status);

//        if ("1".equals(status)) {
        if (!StringUtils.isEmpty(orderId)) {

            try {

                if (!lock(orderId)) {
                    log.error("stormUrl callback is lock");
                    return "error";
                }

                PlatMerOrder order = platMerOrderService.getByOrderId(orderId);
                if (StringUtils.equals(order.getStat(), "2")) {
                    log.info("stormUrl callback order success");
                    return "success";
                }

                PlatMer byMerIdCache = platMerService.getByMerIdCache(order.getMerId());
                if (byMerIdCache == null) {
                    log.info("stormUrl callback plat mer is empty not fund");
                    return "plat mer is empty not fund";
                }

                String md5Str = SecureUtil.md5("app_id=" + byMerIdCache.getMerKey() + "&public_key=" + byMerIdCache.getPublicKey() +
                        "&private_key=" + byMerIdCache.getPrivateKey() + "&total_amount=" + jsonObject.getString("total_amount") +
                        "&out_trade_no=" + jsonObject.getString("out_trade_no") + "&trade_no=" + jsonObject.getString("trade_no"));

                if (md5Str.equals(sign)) {

                    Double pay_money = jsonObject.getBigDecimal("total_amount").doubleValue();
                    /**
                     * 浮动金额
                     */
                    if (order.getAmount().doubleValue() == pay_money.doubleValue()) {

                        int b = platMerOrderService.success(order);

                        if (b > 0) {

                            report(order);
                            log.info("stormUrl success");
                            return "ok";
                        } else {
                            log.error("stormUrl callback error");
                            return "error";
                        }

                    } else {
                        log.error("stormUrl callback amount is error order.getAmount(){} pay_money{}", order.getAmount(), pay_money);
                        return "amount is error";
                    }

                } else {
                    log.error("stormUrl sign error");
                    return "sign error";
                }

            } catch (RuntimeException ex) {
                log.error("stormUrl notify EpayException", ex);
                return "error" + ex.getMessage();
            } catch (Exception ex) {
                log.error("stormUrl callback notify Exception", ex);
                return "system ex ";
            } finally {
                unlock(orderId);
            }
        } else {
            log.error("stormUrl callback plat order is error" + jsonObject.toJSONString());
            return "plat order status is error";
        }
//        } else {
//            log.error("stormUrl status is error" + jsonObject.toJSONString());
//            return "plat order status is error";
//        }
    }

    public String hengshengUrl(JSONObject jsonObject) {
        return jinxinUrl(jsonObject);
    }

    public String jpUrl(JSONObject jsonObject) {
        log.info("jpUrl callback jsonObject " + jsonObject);
        String orderId = jsonObject.getString("orderNo");
        String sign = jsonObject.getString("sign");
        String status = jsonObject.getString("status");
        log.info("jpUrl callback orderid={},sign={},status={}", orderId, sign, status);

        if ("success".equals(status)) {
            if (!StringUtils.isEmpty(orderId)) {

                try {

                    if (!lock(orderId)) {
                        log.error("jpUrl callback is lock");
                        return "error";
                    }

                    PlatMerOrder order = platMerOrderService.getByOrderId(orderId);
                    if (StringUtils.equals(order.getStat(), "2")) {
                        log.info("jpUrl callback order success");
                        return "success";
                    }

                    PlatMer byMerIdCache = platMerService.getByMerIdCache(order.getMerId());
                    if (byMerIdCache == null) {
                        log.info("jpUrl callback plat mer is empty not fund");
                        return "plat mer is empty not fund";
                    }

                    String s = jsonObject.getString("signType") + jsonObject.get("orderNo") + jsonObject.get("orderAmount") +
                            jsonObject.get("orderCurrency") + jsonObject.get("transactionId") + status + byMerIdCache.getPrivateKey();

                    String md5Str = SecureUtil.md5(s);

                    if (md5Str.equals(sign)) {

                        Double pay_money = jsonObject.getBigDecimal("paymentAmount").doubleValue();
                        /**
                         * 浮动金额
                         */
                        if (order.getAmount().doubleValue() == pay_money.doubleValue()) {

                            int b = platMerOrderService.success(order);

                            if (b > 0) {

                                report(order);
                                log.info("jpUrl success");
                                return "success ";
                            } else {
                                log.error("jpUrl callback error");
                                return "error";
                            }

                        } else {
                            log.error("jpUrl callback amount is error order.getAmount(){} pay_money{}", order.getAmount(), pay_money);
                            return "amount is error";
                        }

                    } else {
                        log.error("jpUrl sign error");
                        return "sign error";
                    }

                } catch (RuntimeException ex) {
                    log.error("jpUrl notify EpayException", ex);
                    return "error" + ex.getMessage();
                } catch (Exception ex) {
                    log.error("jpUrl callback notify Exception", ex);
                    return "system ex ";
                } finally {
                    unlock(orderId);
                }
            } else {
                log.error("jpUrl callback plat order is error" + jsonObject.toJSONString());
                return "plat order status is error";
            }
        } else {
            log.error("jpUrl status is error" + jsonObject.toJSONString());
            return "plat order status is error";
        }
    }

    public String fcUrl(JSONObject jsonObject) {
        return pilinUrl(jsonObject);
    }

    public String shoudaoUrl(JSONObject jsonObject) {
        return rrfUrl(jsonObject);
    }

    public String kubeiNew(JSONObject param) throws Exception {
        try {
            String content = param.getString("content");
            String mno = param.getString("mno");


            PlatMer byMerIdCache = platMerService.getByMerIdCache(null, mno);

            AES aes = SecureUtil.aes(byMerIdCache.getWithdrawKey().getBytes());
            log.error("aes jiemi {}", org.apache.commons.codec.binary.Base64.decodeBase64(content));

            byte[] decrypt = aes.decrypt(org.apache.commons.codec.binary.Base64.decodeBase64(content));
            JSONObject contentJson = JSONObject.parseObject(new String(decrypt));
            String sign = contentJson.getString("sign");
            contentJson.remove("sign");
            log.error("content jsson ", contentJson);
            SortedMap sortedMap = new TreeMap();
            for (String key : contentJson.keySet()) {
                sortedMap.put(key, contentJson.getString(key));
            }
            String s = convertUrl(sortedMap, "&", "=");


            String s1 = org.apache.commons.codec.binary.Base64.encodeBase64String(RSAUtils.encryptByPrivateKey(s.getBytes("UTF-8"), byMerIdCache.getPrivateKey()));
//        String resultDecSign  = new String(resultDec);
            log.error("sign result {}", s1);
            log.error("sign encrypt result {}", sign);
            PlatMerOrder order = platMerOrderService.getByOrderId(contentJson.getString("orderno"));

            if (!lock(order.getOrderId())) {
                log.error("jpUrl callback is lock");
                return "error";
            }

            if (StringUtils.equals(order.getStat(), "2")) {
                log.info("jpUrl callback order success");
                return "success";
            }
            if (sign.equals(s1)) {
                Double pay_money = contentJson.getBigDecimal("amount").divide(new BigDecimal(100)).doubleValue();
                /**
                 * 浮动金额
                 */
                if (order.getAmount().doubleValue() == pay_money.doubleValue()) {

                    int b = platMerOrderService.success(order);

                    if (b > 0) {

                        report(order);
                        log.info("jpUrl success");
                        return "success ";
                    } else {
                        log.error("jpUrl callback error");
                        return "error";
                    }

                } else {
                    log.error("jpUrl callback amount is error order.getAmount(){} pay_money{}", order.getAmount(), pay_money);
                    return "amount is error";
                }

            }
            return "error";
        } catch (Exception ex) {
            return "system is error";
        }
    }

    public String fchUrl(JSONObject param) {
        return qfb(param);
    }

    public String kuaixunPay(JSONObject jsonObject) {

        String orderid = jsonObject.getString("out_order_no");
        double amount = jsonObject.getDouble("amount");
        log.error(" order id " + orderid);
        String sign = jsonObject.getString("sign");
        jsonObject.remove("sign");
        jsonObject.remove("attach");
        SortedMap sortedMap = new TreeMap();
        for (String key : jsonObject.keySet()) {

            sortedMap.put(key, jsonObject.getString(key));
        }

        if (StringUtils.isEmpty(orderid)) {

            log.error("plat order id is empty notify order" + orderid);
            return "plat order  order id is empty";
        }


        try {
            if (!lock(orderid)) {
                return "error";
            }


            PlatMerOrder byOrderId = platMerOrderService.getByOrderId(orderid);

            if (StringUtils.equals(byOrderId.getStat(), "2")) {
                return "success";
            }


            double min = byOrderId.getAmount().doubleValue() - 1;
            double max = byOrderId.getAmount().doubleValue() + 1;


            /**
             * 浮动金额
             */
            if (!(amount >= min && amount <= max)) {

//            if (byOrderId.getAmount().doubleValue() != amount) {
                return "amount is  error";
            }

            PlatMer byMerIdCache = platMerService.getByMerIdCache(byOrderId.getMerId());

            if (byMerIdCache == null) {
                return "plat mer is empty not fund";
            }

            String s = convertUrl(sortedMap, "&", "=");
            log.error("sign  url " + s);

            if (!SecureUtil.md5(s + "&key=" + byMerIdCache.getPrivateKey()).toLowerCase().equals(sign)) {
                return "sign error";
            }

            byOrderId.setRealAmount(new BigDecimal(amount));
            int b = platMerOrderService.success(byOrderId);
            if (b > 0) {


                report(byOrderId);

                return "success";
            }
            return "error";

        } catch (RuntimeException ex) {
            log.error("notify EpayException", ex);
            return "error" + ex.getMessage();
        } catch (Exception ex) {
            log.error("notify Exception", ex);
            return "system ex ";
        } finally {
            unlock(orderid);
        }

    }


    public String heshunUrl(JSONObject jsonObject) {
        log.info("jpUrl callback jsonObject " + jsonObject);
        String orderId = jsonObject.getString("orderId");
        String sign = jsonObject.getString("sign");
        String status = jsonObject.getString("status");
        log.info("jpUrl callback orderid={},sign={},status={}", orderId, sign, status);

//        if ("success".equals(status)) {
        if (!StringUtils.isEmpty(orderId)) {

            try {

                if (!lock(orderId)) {
                    log.error("jpUrl callback is lock");
                    return "error";
                }

                PlatMerOrder order = platMerOrderService.getByOrderId(orderId);
                if (StringUtils.equals(order.getStat(), "2")) {
                    log.info("jpUrl callback order success");
                    return "success";
                }

                PlatMer byMerIdCache = platMerService.getByMerIdCache(order.getMerId());
                if (byMerIdCache == null) {
                    log.info("jpUrl callback plat mer is empty not fund");
                    return "plat mer is empty not fund";
                }


                String s = "orderId=" + jsonObject.getString("orderId") +
                        "&userId=" + jsonObject.getString("userId") +
                        "&money=" + jsonObject.getString("money") +
                        "&type=" + jsonObject.getString("type") +
                        byMerIdCache.getPrivateKey();

                String md5Str = SecureUtil.md5(s);

                if (md5Str.equals(sign)) {

                    Double pay_money = jsonObject.getBigDecimal("money").doubleValue();
                    /**
                     * 浮动金额
                     */
                    if (order.getAmount().doubleValue() == pay_money.doubleValue()) {

                        int b = platMerOrderService.success(order);

                        if (b > 0) {

                            report(order);
                            log.info("jpUrl success");
                            return "ok";
                        } else {
                            log.error("jpUrl callback error");
                            return "error";
                        }

                    } else {
                        log.error("jpUrl callback amount is error order.getAmount(){} pay_money{}", order.getAmount(), pay_money);
                        return "amount is error";
                    }

                } else {
                    log.error("jpUrl sign error");
                    return "sign error";
                }

            } catch (RuntimeException ex) {
                log.error("jpUrl notify EpayException", ex);
                return "error" + ex.getMessage();
            } catch (Exception ex) {
                log.error("jpUrl callback notify Exception", ex);
                return "system ex ";
            } finally {
                unlock(orderId);
            }
//            } else {
//                log.error("jpUrl callback plat order is error" + jsonObject.toJSONString());
//                return "plat order status is error";
//            }
        } else {
            log.error("jpUrl status is error" + jsonObject.toJSONString());
            return "plat order status is error";
        }
    }

    public String dysfUrl(JSONObject jsonObject) {
        String orderId = jsonObject.getString("ordernumber");
        String status = jsonObject.getString("orderstatus");
        String sign = jsonObject.getString("sign");
        log.info(String.format("orderId=%s, status=%s, sign=%s", orderId, status, sign));

        if ("1".equals(status)) {

            if (!StringUtils.isEmpty(orderId)) {

                try {

                    if (!lock(orderId)) {
                        log.error("hongYi is lock");
                        return "error";
                    }

                    PlatMerOrder order = platMerOrderService.getByOrderId(orderId);
                    if (StringUtils.equals(order.getStat(), "2")) {
                        log.info("hongyi success");
                        return "success";
                    }

                    PlatMer byMerIdCache = platMerService.getByMerIdCache(order.getMerId());
                    if (byMerIdCache == null) {
                        log.info("hongyi plat mer is empty not fund");
                        return "plat mer is empty not fund";
                    }

                    String s = "partner=" + jsonObject.getString("partner") + "&ordernumber=" + jsonObject.getString("ordernumber") +
                            "&orderstatus=" + status + "&paymoney=" + jsonObject.getString("paymoney") + "&sysnumber=" + jsonObject.getString("sysnumber") + byMerIdCache.getPrivateKey();
                    String md5Str = SecureUtil.md5(s);
                    log.info("hongYi s " + s);
                    log.info("hongYi md5(s) " + md5Str);

                    if (md5Str.toLowerCase().equals(sign)) {

                        if (order.getAmount().doubleValue() == jsonObject.getDouble("paymoney")) {

                            int b = platMerOrderService.success(order);

                            if (b > 0) {
                                report(order);
                                log.info("hongyi callback success");
                                return "ok";
                            } else {
                                log.error("error");
                                return "error";
                            }

                        } else {
                            log.error("amount is error");
                            return "amount is error";
                        }

                    } else {
                        log.error("sign error");
                        return "sign error";
                    }

                } catch (RuntimeException ex) {
                    log.error("notify EpayException", ex);
                    return "error" + ex.getMessage();
                } catch (Exception ex) {
                    log.error("notify Exception", ex);
                    return "system ex ";
                } finally {
                    unlock(orderId);
                }

            } else {
                log.error("plat order id is empty" + orderId);
                return "plat order id is empty";
            }

        } else {
            log.error("plat order is error" + jsonObject.toJSONString());
            return "plat order status is error";
        }

    }

    public String wantengUrl(JSONObject jsonObject) {
        return rrfUrl(jsonObject);
    }

    public String siUrl(JSONObject jsonObject) {
        log.info("jsonObject {}", jsonObject);
        String merchOrder = jsonObject.getString("orderNo");

        String status = jsonObject.getString("state");
        String sign = jsonObject.getString("sign");

        //message
        jsonObject.remove("sign");

        if (!status.equals("1")) {
            log.error("plat order is error" + jsonObject.toJSONString());
            return "plat order status is error";
        }


        if (StringUtils.isEmpty(merchOrder)) {

            log.error("plat order id is empty" + merchOrder);
            return "plat order id is empty";
        }

        try {
            if (!lock(merchOrder)) {
                return "error";
            }


            PlatMerOrder byOrderId = platMerOrderService.getByOrderId(merchOrder);

            if (StringUtils.equals(byOrderId.getStat(), "2")) {
                return "SUCCESS";
            }

            PlatMer byMerIdCache = platMerService.getByMerIdCache(byOrderId.getMerId());

            if (byMerIdCache == null) {
                return "plat mer is empty not fund";
            }

            String s = jsonObject.getString("state") + byMerIdCache.getMerKey() + jsonObject.getString("orderNo") + jsonObject.getString("amount") + byMerIdCache.getPrivateKey();
            log.info(" s {}", s);
//            String sign = SecureUtil.md5(s +"&"+ byMerIdCache.getPrivateKey()).toLowerCase();
            if (!SecureUtil.md5(s).toLowerCase().equals(sign)) {
                return "sign error ";
            }


            if (byOrderId.getAmount().doubleValue() != jsonObject.getDouble("amount")) {
                return "amount is  error";
            }

            int b = platMerOrderService.success(byOrderId);
            if (b > 0) {


                report(byOrderId);

                return "success";
            }
            return "error";

        } catch (RuntimeException ex) {
            log.error("notify EpayException", ex);
            return "error" + ex.getMessage();
        } catch (Exception ex) {
            log.error("notify Exception", ex);
            return "system ex ";
        } finally {
            unlock(merchOrder);
        }
    }

    public String mnashangUrl(JSONObject jsonObject) {
        log.info("mnashangUrl callback jsonObject " + jsonObject);
        String orderId = jsonObject.getString("merchantOrderId");
        String sign = jsonObject.getString("sign");
        String status = jsonObject.getString("status");
        log.info("mnashangUrl callback orderid={},sign={},status={}", orderId, sign, status);

        if ("Success".equals(status)) {
            if (!StringUtils.isEmpty(orderId)) {

                try {

                    if (!lock(orderId)) {
                        log.error("mnashangUrl callback is lock");
                        return "error";
                    }

                    PlatMerOrder order = platMerOrderService.getByOrderId(orderId);
                    if (StringUtils.equals(order.getStat(), "2")) {
                        log.info("mnashangUrl callback order success");
                        return "success";
                    }

                    PlatMer byMerIdCache = platMerService.getByMerIdCache(order.getMerId());
                    if (byMerIdCache == null) {
                        log.info("mnashangUrl callback plat mer is empty not fund");
                        return "plat mer is empty not fund";
                    }

                    jsonObject.remove("sign");
                    SortedMap sortedMap = new TreeMap();
                    for (String key : jsonObject.keySet()) {
                        sortedMap.put(key, jsonObject.getString(key));
                    }
                    sortedMap.put("mp", null);
                    String s = convertUrlIsEmpty(sortedMap, "|", "=") + byMerIdCache.getPrivateKey();
                    log.info("s {}", s);
                    String md5Str = SecureUtil.md5(s);
                    log.info("sign {}", md5Str);

                    if (md5Str.equals(sign)) {

                        Double pay_money = jsonObject.getBigDecimal("actualPayAmount").doubleValue();
                        /**
                         * 浮动金额
                         */
                        if (order.getAmount().doubleValue() == pay_money.doubleValue()) {

                            int b = platMerOrderService.success(order);

                            if (b > 0) {

                                report(order);
                                log.info("mnashangUrl SUCCESS");
                                return "SUCCESS";
                            } else {
                                log.error("mnashangUrl callback error");
                                return "error";
                            }

                        } else {
                            log.error("mnashangUrl callback amount is error order.getAmount(){} pay_money{}", order.getAmount(), pay_money);
                            return "amount is error";
                        }

                    } else {
                        log.error("mnashangUrl sign error");
                        return "sign error";
                    }

                } catch (RuntimeException ex) {
                    log.error("mnashangUrl notify EpayException", ex);
                    return "error" + ex.getMessage();
                } catch (Exception ex) {
                    log.error("mnashangUrl callback notify Exception", ex);
                    return "system ex ";
                } finally {
                    unlock(orderId);
                }
            } else {
                log.error("mnashangUrl callback plat order is error" + jsonObject.toJSONString());
                return "plat order status is error";
            }
        } else {
            log.error("mnashangUrl status is error" + jsonObject.toJSONString());
            return "plat order status is error";
        }
    }

    private static final int MAX_DECRYPT_BLOCK = 128;

    private static final int MAX_ENCRYPT_BLOCK = 117;

    private String decrypt(String crypt, String myPrivateKey) throws Exception {

        myPrivateKey = myPrivateKey.replaceAll("\\s*|\t|\r|\n", "");
        byte[] keyBytes = java.util.Base64.getDecoder().decode(myPrivateKey.getBytes("UTF-8"));
        PKCS8EncodedKeySpec spec = new PKCS8EncodedKeySpec(keyBytes);
        KeyFactory keyFactory = KeyFactory.getInstance("RSA");
        PrivateKey key = keyFactory.generatePrivate(spec);

        Cipher cipher = Cipher.getInstance("RSA");
        cipher.init(Cipher.DECRYPT_MODE, key);
        byte[] dataBytes = java.util.Base64.getDecoder().decode(crypt);
        int inputLen = dataBytes.length;
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        int offset = 0;
        byte[] cache;
        int i = 0;
        // 对数据分段解密
        while (inputLen - offset > 0) {
            if (inputLen - offset > MAX_DECRYPT_BLOCK) {
                cache = cipher.doFinal(dataBytes, offset, MAX_DECRYPT_BLOCK);
            } else {
                cache = cipher.doFinal(dataBytes, offset, inputLen - offset);
            }
            out.write(cache, 0, cache.length);
            i++;
            offset = i * MAX_DECRYPT_BLOCK;
        }
        byte[] decryptedData = out.toByteArray();
        out.close();
        // 解密后的内容
        return new String(decryptedData, "UTF-8");


    }

    private String sign(Map<String, Object> map, String privateKey) throws Exception {

        StringBuffer sb = new StringBuffer();
        ArrayList<String> mapKeys = new ArrayList<String>(map.keySet());
        Collections.sort(mapKeys);
        for (String key : mapKeys) {
            Object value = map.get(key);
            if (value == null || com.alibaba.druid.util.StringUtils.isEmpty(value.toString())) {
                continue;
            }
            sb.append(value);
        }

        String signStr = sb.toString();
        log.error("sign url " + signStr);
        privateKey = privateKey.replaceAll("\\s*|\t|\r|\n", "");
        byte[] keyBytes = java.util.Base64.getDecoder().decode(privateKey.getBytes("UTF-8"));
        PKCS8EncodedKeySpec spec = new PKCS8EncodedKeySpec(keyBytes);
        KeyFactory keyFactory = KeyFactory.getInstance("RSA");
        PrivateKey signKey = keyFactory.generatePrivate(spec);
        Signature signature = Signature.getInstance("SHA1withRSA");
        signature.initSign(signKey);
        signature.update(signStr.getBytes());

        String sign = byteArray2HexString(signature.sign()).toUpperCase();
        return sign;
    }

    public static boolean verify(String data, String publicKey, String sign) throws Exception {
        publicKey = publicKey.replaceAll("\\s*|\t|\r|\n", "");
        byte[] keyBytes = org.apache.commons.codec.binary.Base64.decodeBase64(publicKey);
        X509EncodedKeySpec keySpec = new X509EncodedKeySpec(keyBytes);
        KeyFactory keyFactory = KeyFactory.getInstance("RSA");
        PublicKey publicK = keyFactory.generatePublic(keySpec);
        Signature signature = Signature.getInstance("SHA1withRSA");
        signature.initVerify(publicK);
        signature.update(data.getBytes());
        return signature.verify(hexStrToByteArray(sign));
    }

    public static byte[] hexStrToByteArray(String str) {
        if (str == null) {
            return null;
        }
        if (str.length() == 0) {
            return new byte[0];
        }
        byte[] byteArray = new byte[str.length() / 2];
        for (int i = 0; i < byteArray.length; i++) {
            String subStr = str.substring(2 * i, 2 * i + 2);
            byteArray[i] = ((byte) Integer.parseInt(subStr, 16));
        }
        return byteArray;
    }

    private static String byteArray2HexString(byte arr[]) {
        StringBuilder sbd = new StringBuilder();
        for (byte b : arr) {
            String tmp = Integer.toHexString(0xff & b);
            if (tmp.length() < 2)
                tmp = (new StringBuilder()).append("0").append(tmp).toString();
            sbd.append(tmp);
        }
        return sbd.toString();
    }

    public String knUrl(JSONObject jsonObject) {
        log.info("knUrl callback jsonObject " + jsonObject);

        String content = jsonObject.getString("content");
        PlatMer byMerIdCache = platMerService.getByMerIdCache(null, jsonObject.getString("merchantCode"));

        String decrypt = null;
        try {
            decrypt = decrypt(content, byMerIdCache.getPrivateKey().replaceAll(" ", ""));
        } catch (Exception e) {
            e.printStackTrace();
        }
        JSONObject map = JSON.parseObject(decrypt);
        log.error("sign url+ {}", map.toJSONString());
        String orderId = map.getString("merchantTradeNo");


        String status = map.getString("tradeStatus");

        String sign = map.getString("sign");
        if ("PAYMENT_SUCCESS".equals(status)) {
            if (!StringUtils.isEmpty(orderId)) {

                try {

                    if (!lock(orderId)) {
                        log.error("knUrl callback is lock");
                        return "error";
                    }

                    PlatMerOrder order = platMerOrderService.getByOrderId(orderId);
                    if (StringUtils.equals(order.getStat(), "2")) {
                        log.info("knUrl callback order success");
                        return "success";
                    }

                    if (byMerIdCache == null) {
                        log.info("knUrl callback plat mer is empty not fund");
                        return "plat mer is empty not fund";
                    }

                    map.remove("sign");
                    Map<String, Object> sortedMap = new TreeMap();
                    for (String key : map.keySet()) {
                        sortedMap.put(key, map.getString(key));
                    }

                    StringBuffer sb = new StringBuffer();
                    ArrayList<String> mapKeys = new ArrayList<String>(map.keySet());
                    Collections.sort(mapKeys);
                    for (String key : mapKeys) {
                        Object value = map.get(key);
                        if (value == null || com.alibaba.druid.util.StringUtils.isEmpty(value.toString())) {
                            continue;
                        }
                        sb.append(value);
                    }
                    log.error("sign url+ {}", verify(sb.toString(), byMerIdCache.getPublicKey().replaceAll(" ", ""), sign));
//                    log.error("sign private"+byMerIdCache.getPrivateKey());
//                    String result = sign(sortedMap,  byMerIdCache.getPrivateKey().replaceAll(" ",""));
//                    sb.append(byMerIdCache.getPrivateKey());
                    log.error("result sign {}", sign);


                    if (verify(sb.toString(), byMerIdCache.getPublicKey().replaceAll(" ", ""), sign)) {

                        Double pay_money = map.getDouble("amount");
                        /**
                         * 浮动金额
                         */
                        if (order.getAmount().doubleValue() == pay_money.doubleValue()) {

                            int b = platMerOrderService.success(order);

                            if (b > 0) {

                                report(order);
                                log.info("knUrl SUCCESS");
                                return "SUCCESS";
                            } else {
                                log.error("knUrl callback error");
                                return "error";
                            }

                        } else {
                            log.error("knUrl callback amount is error order.getAmount(){} pay_money{}", order.getAmount(), pay_money);
                            return "amount is error";
                        }

                    } else {
                        log.error("knUrl sign error");
                        return "sign error";
                    }

                } catch (RuntimeException ex) {
                    log.error("knUrl notify EpayException", ex);
                    return "error" + ex.getMessage();
                } catch (Exception ex) {
                    log.error("knUrl callback notify Exception", ex);
                    return "system ex ";
                } finally {
                    unlock(orderId);
                }
            } else {
                log.error("knUrl callback plat order is error" + jsonObject.toJSONString());
                return "plat order status is error";
            }
        } else {
            log.error("knUrl status is error" + jsonObject.toJSONString());
            return "plat order status is error";
        }
    }

    private String encrypt(String content, String peerPublicKey) throws Exception {
        peerPublicKey = peerPublicKey.replaceAll("\\s*|\t|\r|\n", "");
        byte[] keyBytes = java.util.Base64.getDecoder().decode(peerPublicKey.getBytes());
        X509EncodedKeySpec bobPubKeySpec = new X509EncodedKeySpec(keyBytes);
        KeyFactory keyFactory = KeyFactory.getInstance("RSA");
        PublicKey key = keyFactory.generatePublic(bobPubKeySpec);

        Cipher cipher = Cipher.getInstance("RSA");
        cipher.init(Cipher.ENCRYPT_MODE, key);
        int inputLen = content.getBytes().length;
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        int offset = 0;
        byte[] cache;
        int i = 0;
        // 对数据分段加密
        while (inputLen - offset > 0) {
            if (inputLen - offset > MAX_ENCRYPT_BLOCK) {
                cache = cipher.doFinal(content.getBytes(), offset, MAX_ENCRYPT_BLOCK);
            } else {
                cache = cipher.doFinal(content.getBytes(), offset, inputLen - offset);
            }
            out.write(cache, 0, cache.length);
            i++;
            offset = i * MAX_ENCRYPT_BLOCK;
        }
        byte[] encryptedData = out.toByteArray();
        out.close();
        // 获取加密内容使用base64进行编码,并以UTF-8为标准转化成字符串
        // 加密后的字符串
        String encData = new String(java.util.Base64.getEncoder().encode(encryptedData));
        System.out.println(content + "," + encData);
        return encData;
    }

    public String abUrl(JSONObject jsonObject) {
        log.info("mnashangUrl callback jsonObject " + jsonObject);
        String orderId = jsonObject.getString("apporderid");
        String sign = jsonObject.getString("hmac");
        String status = jsonObject.getString("status");
//        log.info("mnashangUrl callback orderid={},sign={},status={}", orderId, sign, status);
        log.info("mnashangUrl callback orderid={},sign={}", orderId, sign);

        if ("0".equals(status)) {
            if (!StringUtils.isEmpty(orderId)) {

                try {

                    if (!lock(orderId)) {
                        log.error("mnashangUrl callback is lock");
                        return "error";
                    }

                    PlatMerOrder order = platMerOrderService.getByOrderId(orderId);
                    if (StringUtils.equals(order.getStat(), "2")) {
                        log.info("mnashangUrl callback order success");
                        return "success";
                    }

                    PlatMer byMerIdCache = platMerService.getByMerIdCache(order.getMerId());
                    if (byMerIdCache == null) {
                        log.info("mnashangUrl callback plat mer is empty not fund");
                        return "plat mer is empty not fund";
                    }

                    jsonObject.remove("hmac");
                    SortedMap sortedMap = new TreeMap();
                    for (String key : jsonObject.keySet()) {
                        sortedMap.put(key, jsonObject.getString(key));
                    }
                    log.info("map {}", sortedMap);

                    String s = convertUrl(sortedMap, "&", "=");
                    log.info("s {}", s);

                    log.info("platMer.getPrivateKey() {}", byMerIdCache.getPrivateKey());
                    String hmac = getKeyedDigestUTF8(s, byMerIdCache.getPrivateKey()).toLowerCase();


                    if (hmac.equals(sign)) {

                        Double pay_money = jsonObject.getBigDecimal("realamount").doubleValue();
                        /**
                         * 浮动金额
                         */
                        if (order.getAmount().doubleValue() == pay_money.doubleValue()) {

                            int b = platMerOrderService.success(order);

                            if (b > 0) {

                                report(order);
                                log.info("mnashangUrl SUCCESS");
                                return "success";
                            } else {
                                log.error("mnashangUrl callback error");
                                return "error";
                            }

                        } else {
                            log.error("mnashangUrl callback amount is error order.getAmount(){} pay_money{}", order.getAmount(), pay_money);
                            return "amount is error";
                        }

                    } else {
                        log.error("mnashangUrl sign error");
                        return "sign error";
                    }

                } catch (RuntimeException ex) {
                    log.error("mnashangUrl notify EpayException", ex);
                    return "error" + ex.getMessage();
                } catch (Exception ex) {
                    log.error("mnashangUrl callback notify Exception", ex);
                    return "system ex ";
                } finally {
                    unlock(orderId);
                }
            } else {
                log.error("mnashangUrl callback plat order is error" + jsonObject.toJSONString());
                return "plat order status is error";
            }
        } else {
            log.error("mnashangUrl status is error" + jsonObject.toJSONString());
            return "plat order status is error";
        }
    }

    public static String getKeyedDigestUTF8(String strSrc, String key) {
        try {
            MessageDigest md5 = MessageDigest.getInstance("MD5");
            md5.update(strSrc.getBytes("UTF8"));
            String result = "";
            byte[] temp;
            temp = md5.digest(key.getBytes("UTF8"));
            for (int i = 0; i < temp.length; i++)
                result += Integer.toHexString((0x000000ff & temp[i]) | 0xffffff00).substring(6);
            return result;
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    public String tudouUrl(JSONObject jsonObject) {
        return theUrl(jsonObject);
    }

    public String facaizfPay(JSONObject jsonObject) {
        return XGPay(jsonObject);
    }

    public String qianchengUrl(JSONObject jsonObject) {
        return yinFuTong(jsonObject);
    }

    public String shayuUrl(JSONObject jsonObject) {
        log.info("shayuUrl callback jsonObject " + jsonObject);
        String orderId = jsonObject.getString("orderno");
        String sign = jsonObject.getString("sign");
        String status = jsonObject.getString("paystatus");
        log.info("shayuUrl callback orderid={},sign={},status={}", orderId, sign, status);

        if ("1".equals(status)) {
            if (!StringUtils.isEmpty(orderId)) {

                try {

                    if (!lock(orderId)) {
                        log.error("shayuUrl callback is lock");
                        return "error";
                    }

                    PlatMerOrder order = platMerOrderService.getByOrderId(orderId);
                    if (StringUtils.equals(order.getStat(), "2")) {
                        log.info("shayuUrl callback order success");
                        return "success";
                    }

                    PlatMer byMerIdCache = platMerService.getByMerIdCache(order.getMerId());
                    if (byMerIdCache == null) {
                        log.info("shayuUrl callback plat mer is empty not fund");
                        return "plat mer is empty not fund";
                    }

//                    jsonObject.remove("sign");
//                    SortedMap sortedMap = new TreeMap();
//                    for (String key : jsonObject.keySet()) {
//                        if (key.equals("paytime")) {
//                            sortedMap.put(key, Convert.toStr(jsonObject.getDate(key).getTime()));
//                        } else {
//                            sortedMap.put(key, jsonObject.getString(key));
//                        }
//                    }
                    String s = "orderid=" + jsonObject.getString("orderid") + "&orderno=" + jsonObject.getString("orderno") +
                            "&paytype=" + jsonObject.getString("paytype") + "&amount=" + jsonObject.getString("amount") +
                            "&payfee=" + jsonObject.getString("payfee") + "&payno=" + jsonObject.getString("payno") +
                            "&payamount=" + jsonObject.getString("payamount") + "&paystatus=" + jsonObject.getString("paystatus") +
                            "&paytime=" + jsonObject.getString("paytime") + byMerIdCache.getPrivateKey();
                    log.info("shayuUrl s {}", s);
                    String md5Str = SecureUtil.md5(s).toUpperCase();
                    log.info("shayuUrl sign {}", md5Str);

                    if (md5Str.equals(sign)) {

                        Double pay_money = jsonObject.getBigDecimal("payamount").doubleValue();
                        /**
                         * 浮动金额
                         */
                        if (order.getAmount().doubleValue() == new BigDecimal(pay_money).divide(new BigDecimal(100)).doubleValue()) {

                            int b = platMerOrderService.success(order);

                            if (b > 0) {

                                report(order);
                                log.info("shayuUrl SUCCESS");
                                return "success";
                            } else {
                                log.error("shayuUrl callback error");
                                return "error";
                            }

                        } else {
                            log.error("shayuUrl callback amount is error order.getAmount(){} pay_money{}", order.getAmount(), pay_money);
                            return "amount is error";
                        }

                    } else {
                        log.error("shayuUrl sign error");
                        return "sign error";
                    }

                } catch (RuntimeException ex) {
                    log.error("shayuUrl notify EpayException", ex);
                    return "error" + ex.getMessage();
                } catch (Exception ex) {
                    log.error("shayuUrl callback notify Exception", ex);
                    return "system ex ";
                } finally {
                    unlock(orderId);
                }
            } else {
                log.error("shayuUrl callback plat order is error" + jsonObject.toJSONString());
                return "plat order status is error";
            }
        } else {
            log.error("shayuUrl status is error" + jsonObject.toJSONString());
            return "plat order status is error";
        }
    }

    public String jzfUrl(JSONObject jsonObject) {
        return rrfUrl(jsonObject);
    }

    public String zhfUrl(JSONObject jsonObject) {
        return shejiao(jsonObject);
    }

    public String mianqianUrl(JSONObject jsonObject) {
        return dxerUrl(jsonObject);
    }

    public String ronghuixinUrl(JSONObject jsonObject) {
        log.info("ronghuixin callback jsonObject " + jsonObject);
        String orderId = jsonObject.getString("outTradeNo");
        String sign = jsonObject.getString("sign");
        String status = jsonObject.getString("status");
        log.info("ronghuixin callback orderid={},sign={},status={}", orderId, sign, status);

//        if ("Success".equals(status)) {
        if (!StringUtils.isEmpty(orderId)) {

            try {

                if (!lock(orderId)) {
                    log.error("ronghuixin callback is lock");
                    return "error";
                }

                PlatMerOrder order = platMerOrderService.getByOrderId(orderId);
                if (StringUtils.equals(order.getStat(), "2")) {
                    log.info("ronghuixin callback order success");
                    return "success";
                }

                PlatMer byMerIdCache = platMerService.getByMerIdCache(order.getMerId());
                if (byMerIdCache == null) {
                    log.info("ronghuixin callback plat mer is empty not fund");
                    return "plat mer is empty not fund";
                }

                jsonObject.remove("sign");
                SortedMap sortedMap = new TreeMap();
                for (String key : jsonObject.keySet()) {
                    sortedMap.put(key, jsonObject.getString(key));
                }
                sortedMap.put("token", byMerIdCache.getPrivateKey());
                String s = convertUrlIsEmpty(sortedMap, "&", "=");
                log.info("s {}", s);
                String md5Str = SecureUtil.md5(s).toUpperCase();
                log.info("sign {}", md5Str);

                if (md5Str.equals(sign)) {

                    Double pay_money = jsonObject.getBigDecimal("realMoney").doubleValue();
                    /**
                     * 浮动金额
                     */
                    if (order.getAmount().doubleValue() == pay_money.doubleValue()) {

                        int b = platMerOrderService.success(order);

                        if (b > 0) {

                            report(order);
                            log.info("ronghuixin SUCCESS");
                            return "SUCCESS";
                        } else {
                            log.error("ronghuixin callback error");
                            return "error";
                        }

                    } else {
                        log.error("ronghuixin callback amount is error order.getAmount(){} pay_money{}", order.getAmount(), pay_money);
                        return "amount is error";
                    }

                } else {
                    log.error("ronghuixin sign error");
                    return "sign error";
                }

            } catch (RuntimeException ex) {
                log.error("ronghuixin notify EpayException", ex);
                return "error" + ex.getMessage();
            } catch (Exception ex) {
                log.error("ronghuixin callback notify Exception", ex);
                return "system ex ";
            } finally {
                unlock(orderId);
            }
//            } else {
//                log.error("ronghuixin callback plat order is error" + jsonObject.toJSONString());
//                return "plat order status is error";
//            }
        } else {
            log.error("ronghuixin status is error" + jsonObject.toJSONString());
            return "plat order status is error";
        }
    }

    public String kuaijieUrl(JSONObject jsonObject) {
        log.info("kuaijie callback jsonObject " + jsonObject);

        String unDecodeStr = RechargeServiceImpl.UnPackUrlBase64(jsonObject.getString("context"));
        BASE64Decoder unBase64 = new BASE64Decoder(); //unBase64
        byte[] unByte = null;
        try {
            unByte = unBase64.decodeBuffer(unDecodeStr);
        } catch (IOException e) {
            e.printStackTrace();
        }

        unDecodeStr = null;
        try {
            unDecodeStr = new String(unByte, "GBK");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        System.out.println(unDecodeStr);

        Map<String, String> map = RechargeServiceImpl.url2Map(unDecodeStr);
        log.info("map {}", map);

        String orderId = map.get("app_id");
        String sign = map.get("signature");
        String status = map.get("result");

        log.info("kuaijie callback orderid={},sign={},status={}", orderId, sign, status);

        if ("1".equals(status)) {
            if (!StringUtils.isEmpty(orderId)) {

                try {

                    if (!lock(orderId)) {
                        log.error("kuaijie callback is lock");
                        return "error";
                    }

                    PlatMerOrder order = platMerOrderService.getByOrderId(orderId);
                    if (StringUtils.equals(order.getStat(), "2")) {
                        log.info("kuaijie callback order success");
                        return "success";
                    }

                    PlatMer byMerIdCache = platMerService.getByMerIdCache(order.getMerId());
                    if (byMerIdCache == null) {
                        log.info("kuaijie callback plat mer is empty not fund");
                        return "plat mer is empty not fund";
                    }

                    StringBuffer buf = new StringBuffer();
                    buf.setLength(0);
                    buf.append("{" + map.get("trans_id") + "}|{");
                    buf.append(map.get("result") + "}|{");
                    buf.append(map.get("amount") + "}|{");
                    buf.append(byMerIdCache.getPrivateKey() + "}");

                    String Retsign = (RechargeServiceImpl.getKeyedDigest(buf.toString())).substring(0, 16).toUpperCase();
                    log.info("s {}", buf.toString());
                    log.info("sign {}", Retsign);

                    if (Retsign.equals(sign)) {

                        Double pay_money = new BigDecimal(map.get("amount")).divide(new BigDecimal(100)).doubleValue();
                        /**
                         * 浮动金额
                         */
                        if (order.getAmount().doubleValue() == pay_money.doubleValue()) {

                            int b = platMerOrderService.success(order);

                            if (b > 0) {

                                report(order);
                                log.info("kuaijie SUCCESS");
                                return "SUCCESS";
                            } else {
                                log.error("ronghuixin callback error");
                                return "error";
                            }

                        } else {
                            log.error("ronghuixin callback amount is error order.getAmount(){} pay_money{}", order.getAmount(), pay_money);
                            return "amount is error";
                        }

                    } else {
                        log.error("ronghuixin sign error");
                        return "sign error";
                    }

                } catch (RuntimeException ex) {
                    log.error("ronghuixin notify EpayException", ex);
                    return "error" + ex.getMessage();
                } catch (Exception ex) {
                    log.error("ronghuixin callback notify Exception", ex);
                    return "system ex ";
                } finally {
                    unlock(orderId);
                }
            } else {
                log.error("ronghuixin callback plat order is error" + jsonObject.toJSONString());
                return "plat order status is error";
            }
        } else {
            log.error("ronghuixin status is error" + jsonObject.toJSONString());
            return "plat order status is error";
        }
    }

    public String haoyunUrl(JSONObject jsonObject) {
        log.info("haoyunUrl callback jsonObject " + jsonObject);
        String orderId = jsonObject.getString("sdorderno");
        String sign = jsonObject.getString("sign");
        String status = jsonObject.getString("status");
        log.info("haoyunUrl callback orderid={},sign={},status={}", orderId, sign, status);
        if (status.equals("0")) {
            jsonObject.remove("status");
        }
        if (!"1".equals(status)) {
            log.error("haoyunUrl status is error");
            return "error";
        }
        if (!StringUtils.isEmpty(orderId)) {

            try {

                if (!lock(orderId)) {
                    log.error("haoyunUrl callback is lock");
                    return "error";
                }

                PlatMerOrder order = platMerOrderService.getByOrderId(orderId);
                if (StringUtils.equals(order.getStat(), "2")) {
                    log.info("haoyunUrl callback order success");
                    return "success";
                }

                PlatMer byMerIdCache = platMerService.getByMerIdCache(order.getMerId());
                if (byMerIdCache == null) {
                    log.info("haoyunUrl callback plat mer is empty not fund");
                    return "plat mer is empty not fund";
                }

                jsonObject.remove("sign");
                SortedMap sortedMap = new TreeMap();
                for (String key : jsonObject.keySet()) {
                    sortedMap.put(key, jsonObject.getString(key));
                }
                String s = convertUrlIsEmpty(sortedMap, "&", "=") + "key=" + byMerIdCache.getPrivateKey();
                log.info("s {}", s);
                String md5Str = SecureUtil.md5(s).toUpperCase();
                log.info("sign {}", md5Str);

                if (md5Str.equalsIgnoreCase(sign)) {

                    Double pay_money = jsonObject.getBigDecimal("total_fee").doubleValue();
                    /**
                     * 浮动金额
                     */
                    if (order.getAmount().doubleValue() == pay_money.doubleValue()) {

                        int b = platMerOrderService.success(order);

                        if (b > 0) {

                            report(order);
                            log.info("haoyunUrl success");
                            return "success";
                        } else {
                            log.error("haoyunUrl callback error");
                            return "error";
                        }

                    } else {
                        log.error("haoyunUrl callback amount is error order.getAmount(){} pay_money{}", order.getAmount(), pay_money);
                        return "amount is error";
                    }

                } else {
                    log.error("haoyunUrl sign error");
                    return "sign error";
                }

            } catch (RuntimeException ex) {
                log.error("haoyunUrl notify EpayException", ex);
                return "error" + ex.getMessage();
            } catch (Exception ex) {
                log.error("haoyunUrl callback notify Exception", ex);
                return "system ex ";
            } finally {
                unlock(orderId);
            }
        } else {
            log.error("ronghuixin callback plat order is error" + jsonObject.toJSONString());
            return "plat order status is error";
        }
//        } else {
//            log.error("haoyunUrl status is error" + jsonObject.toJSONString());
//            return "plat order status is error";
//        }
    }

    public String moqingUrl(JSONObject jsonObject) {
        return yinFuTong(jsonObject);
    }

    public String yundingUrl(JSONObject jsonObject) {
        return dongyayihao(jsonObject);
    }

    public String shandianUrl(JSONObject jsonObject) {
        log.info("shandianUrl callback jsonObject " + jsonObject);
        String orderId = jsonObject.getString("outTradeNo");
        String sign = jsonObject.getString("sign");
        String status = jsonObject.getString("status");
        log.info("shandianUrl callback orderid={},sign={},status={}", orderId, sign, status);
// 121.201.61.249  验证ip
//        if ("Success".equals(status)) {
        if (!StringUtils.isEmpty(orderId)) {

            try {

                if (!lock(orderId)) {
                    log.error("ronghuixin callback is lock");
                    return "error";
                }

                PlatMerOrder order = platMerOrderService.getByOrderId(orderId);
                if (StringUtils.equals(order.getStat(), "2")) {
                    log.info("ronghuixin callback order success");
                    return "success";
                }

                PlatMer byMerIdCache = platMerService.getByMerIdCache(order.getMerId());
                if (byMerIdCache == null) {
                    log.info("ronghuixin callback plat mer is empty not fund");
                    return "plat mer is empty not fund";
                }

                jsonObject.remove("sign");
                SortedMap sortedMap = new TreeMap();
                for (String key : jsonObject.keySet()) {
                    sortedMap.put(key, jsonObject.getString(key));
                }
                sortedMap.put("token", byMerIdCache.getPrivateKey());
                String s = convertUrlIsEmpty(sortedMap, "&", "=");
                log.info("s {}", s);
                String md5Str = SecureUtil.md5(s).toUpperCase();
                log.info("sign {}", md5Str);

                if (md5Str.equals(sign)) {

                    Double pay_money = jsonObject.getBigDecimal("realMoney").doubleValue();
                    /**
                     * 浮动金额
                     */
                    if (order.getAmount().doubleValue() == pay_money.doubleValue()) {

                        int b = platMerOrderService.success(order);

                        if (b > 0) {

                            report(order);
                            log.info("ronghuixin SUCCESS");
                            return "SUCCESS";
                        } else {
                            log.error("ronghuixin callback error");
                            return "error";
                        }

                    } else {
                        log.error("ronghuixin callback amount is error order.getAmount(){} pay_money{}", order.getAmount(), pay_money);
                        return "amount is error";
                    }

                } else {
                    log.error("ronghuixin sign error");
                    return "sign error";
                }

            } catch (RuntimeException ex) {
                log.error("ronghuixin notify EpayException", ex);
                return "error" + ex.getMessage();
            } catch (Exception ex) {
                log.error("ronghuixin callback notify Exception", ex);
                return "system ex ";
            } finally {
                unlock(orderId);
            }
//            } else {
//                log.error("ronghuixin callback plat order is error" + jsonObject.toJSONString());
//                return "plat order status is error";
//            }
        } else {
            log.error("ronghuixin status is error" + jsonObject.toJSONString());
            return "plat order status is error";
        }
    }


    public String kxUrl(JSONObject jsonObject) {
        return kuaixunPay(jsonObject);
    }


    public String shangtian(JSONObject param) throws Exception {

        String orderId = param.getString("orderId");
        if (!lock(orderId)) {
            log.error("haoyunUrl callback is lock");
            return "error";
        }
        PlatMerOrder order = platMerOrderService.getByOrderId(orderId);
        if (StringUtils.equals(order.getStat(), "2")) {
            log.info("haoyunUrl callback order success");
            return "success";
        }
        Double pay_money = param.getBigDecimal("amount").doubleValue();
        if (order.getAmount().doubleValue() == pay_money.doubleValue()) {

            int b = platMerOrderService.success(order);

            if (b > 0) {

                report(order);
                log.info("haoyunUrl success");
                return "success";
            } else {
                log.error("haoyunUrl callback error");
                return "error";
            }

        } else {
            log.error("haoyunUrl callback amount is error order.getAmount(){} pay_money{}", order.getAmount(), pay_money);
            return "amount is error";
        }


    }

    public String kx2Url(JSONObject jsonObject) {
        return kubeiUrl(jsonObject);
    }

    public String yuechuangUrl(JSONObject jsonObject) {
        log.info("mnashangUrl callback jsonObject " + jsonObject);
        String orderId = jsonObject.getString("apporderid");
        String sign = jsonObject.getString("hmac");
        String status = jsonObject.getString("status");
//        log.info("mnashangUrl callback orderid={},sign={},status={}", orderId, sign, status);
        log.info("mnashangUrl callback orderid={},sign={}", orderId, sign);

        if ("0".equals(status)) {
            if (!StringUtils.isEmpty(orderId)) {

                try {

                    if (!lock(orderId)) {
                        log.error("mnashangUrl callback is lock");
                        return "error";
                    }

                    PlatMerOrder order = platMerOrderService.getByOrderId(orderId);
                    if (StringUtils.equals(order.getStat(), "2")) {
                        log.info("mnashangUrl callback order success");
                        return "success";
                    }

                    PlatMer byMerIdCache = platMerService.getByMerIdCache(order.getMerId());
                    if (byMerIdCache == null) {
                        log.info("mnashangUrl callback plat mer is empty not fund");
                        return "plat mer is empty not fund";
                    }


                    jsonObject.remove("hmac");
                    SortedMap sortedMap = new TreeMap();
                    for (String key : jsonObject.keySet()) {
                        sortedMap.put(key, jsonObject.getString(key));
                    }
                    log.info("map {}", sortedMap);

                    String s = convertUrl(sortedMap, "&", "=");
                    log.info("s {}", s);

                    log.info("platMer.getPrivateKey() {}", byMerIdCache.getPrivateKey());
                    String hmac = getKeyedDigestUTF8(s, byMerIdCache.getPrivateKey()).toLowerCase();

                    if (hmac.equals(sign)) {

                        Double pay_money = jsonObject.getBigDecimal("realamount").doubleValue();
                        /**
                         * 浮动金额
                         */
                        if (order.getAmount().doubleValue() == pay_money.doubleValue()) {

                            int b = platMerOrderService.success(order);

                            if (b > 0) {

                                report(order);
                                log.info("mnashangUrl SUCCESS");
                                return "success";
                            } else {
                                log.error("mnashangUrl callback error");
                                return "error";
                            }

                        } else {
                            log.error("mnashangUrl callback amount is error order.getAmount(){} pay_money{}", order.getAmount(), pay_money);
                            return "amount is error";
                        }

                    } else {
                        log.error("mnashangUrl sign error");
                        return "sign error";
                    }

                } catch (RuntimeException ex) {
                    log.error("mnashangUrl notify EpayException", ex);
                    return "error" + ex.getMessage();
                } catch (Exception ex) {
                    log.error("mnashangUrl callback notify Exception", ex);
                    return "system ex ";
                } finally {
                    unlock(orderId);
                }
            } else {
                log.error("mnashangUrl callback plat order is error" + jsonObject.toJSONString());
                return "plat order status is error";
            }
        } else {
            log.error("mnashangUrl status is error" + jsonObject.toJSONString());
            return "plat order status is error";
        }
    }
    public String guangxinUrl(JSONObject jsonObject) {
        log.info("mnashangUrl callback jsonObject " + jsonObject);
        String orderId = jsonObject.getString("outTradeNo");
        String sign = jsonObject.getString("sign");
        String status = jsonObject.getString("resultCode");
//        log.info("mnashangUrl callback orderid={},sign={},status={}", orderId, sign, status);
        log.info("mnashangUrl callback orderid={},sign={}", orderId, sign);

        if ("00".equals(status)) {
            if (!StringUtils.isEmpty(orderId)) {

                try {

                    if (!lock(orderId)) {
                        log.error("mnashangUrl callback is lock");
                        return "error";
                    }

                    PlatMerOrder order = platMerOrderService.getByOrderId(orderId);
                    if (StringUtils.equals(order.getStat(), "2")) {
                        log.info("mnashangUrl callback order success");
                        return "success";
                    }

                    PlatMer byMerIdCache = platMerService.getByMerIdCache(order.getMerId());
                    if (byMerIdCache == null) {
                        log.info("mnashangUrl callback plat mer is empty not fund");
                        return "plat mer is empty not fund";
                    }


                    jsonObject.remove("sign");
                    SortedMap sortedMap = new TreeMap();
                    for (String key : jsonObject.keySet()) {
                        sortedMap.put(key, jsonObject.getString(key));
                    }
                    log.info("map {}", sortedMap);

                    String s = convertUrl(sortedMap, "&", "=") + "&signKey=" + byMerIdCache.getPrivateKey();
                    log.info("s {}", s);

                    String md5Sign = SecureUtil.md5(s);
                    log.info("md5Sign {}", md5Sign);

                    if (md5Sign.equals(sign)) {

                        Double pay_money = jsonObject.getBigDecimal("amount").doubleValue();
                        /**
                         * 浮动金额
                         */
                        if (order.getAmount().doubleValue() == pay_money.doubleValue()) {

                            int b = platMerOrderService.success(order);

                            if (b > 0) {

                                report(order);
                                log.info("mnashangUrl SUCCESS");
                                return "success";
                            } else {
                                log.error("mnashangUrl callback error");
                                return "error";
                            }

                        } else {
                            log.error("mnashangUrl callback amount is error order.getAmount(){} pay_money{}", order.getAmount(), pay_money);
                            return "amount is error";
                        }

                    } else {
                        log.error("mnashangUrl sign error");
                        return "sign error";
                    }

                } catch (RuntimeException ex) {
                    log.error("mnashangUrl notify EpayException", ex);
                    return "error" + ex.getMessage();
                } catch (Exception ex) {
                    log.error("mnashangUrl callback notify Exception", ex);
                    return "system ex ";
                } finally {
                    unlock(orderId);
                }
            } else {
                log.error("mnashangUrl callback plat order is error" + jsonObject.toJSONString());
                return "plat order status is error";
            }
        } else {
            log.error("mnashangUrl status is error" + jsonObject.toJSONString());
            return "plat order status is error";
        }
    }

    public String kUrl(JSONObject jsonObject) {
        log.info("mnashangUrl callback jsonObject " + jsonObject);
        String orderId = jsonObject.getString("outOrderId");
        String sign = jsonObject.getString("sign");
        String status = jsonObject.getString("status");
//        log.info("mnashangUrl callback orderid={},sign={},status={}", orderId, sign, status);
        log.info("mnashangUrl callback orderid={},sign={}", orderId, sign);

        if ("5".equals(status)) {
            if (!StringUtils.isEmpty(orderId)) {

                try {

                    if (!lock(orderId)) {
                        log.error("mnashangUrl callback is lock");
                        return "error";
                    }

                    PlatMerOrder order = platMerOrderService.getByOrderId(orderId);
                    if (StringUtils.equals(order.getStat(), "2")) {
                        log.info("mnashangUrl callback order success");
                        return "success";
                    }

                    PlatMer byMerIdCache = platMerService.getByMerIdCache(order.getMerId());
                    if (byMerIdCache == null) {
                        log.info("mnashangUrl callback plat mer is empty not fund");
                        return "plat mer is empty not fund";
                    }

                    String s = jsonObject.getString("nickname") + jsonObject.getString("customerAmountCny")
                            + jsonObject.getString("outOrderId") + jsonObject.getString("orderId")
                            + jsonObject.getString("signType") + jsonObject.getString("status")
                            + byMerIdCache.getPrivateKey();
                    log.info("s {}", s);

                    String md5Sign = SecureUtil.md5(s);
                    log.info("md5Sign {}", md5Sign);

                    if (md5Sign.equals(sign)) {

                        Double pay_money = jsonObject.getBigDecimal("customerAmountCny").doubleValue();
                        /**
                         * 浮动金额
                         */
                        if (order.getAmount().doubleValue() == pay_money.doubleValue()) {

                            int b = platMerOrderService.success(order);

                            if (b > 0) {

                                report(order);
                                log.info("mnashangUrl SUCCESS");
                                return "success";
                            } else {
                                log.error("mnashangUrl callback error");
                                return "error";
                            }

                        } else {
                            log.error("mnashangUrl callback amount is error order.getAmount(){} pay_money{}", order.getAmount(), pay_money);
                            return "amount is error";
                        }

                    } else {
                        log.error("mnashangUrl sign error");
                        return "sign error";
                    }

                } catch (RuntimeException ex) {
                    log.error("mnashangUrl notify EpayException", ex);
                    return "error" + ex.getMessage();
                } catch (Exception ex) {
                    log.error("mnashangUrl callback notify Exception", ex);
                    return "system ex ";
                } finally {
                    unlock(orderId);
                }
            } else {
                log.error("mnashangUrl callback plat order is error" + jsonObject.toJSONString());
                return "plat order status is error";
            }
        } else {
            log.error("mnashangUrl status is error" + jsonObject.toJSONString());
            return "plat order status is error";
        }
    }

    public String wanxiangUrl(JSONObject jsonObject) {
        log.info("haoyunUrl callback jsonObject " + jsonObject);
        String orderId = jsonObject.getString("orderNo");
        String sign = jsonObject.getString("sign");
        String status = jsonObject.getString("returnCode");
        log.info("haoyunUrl callback orderid={},sign={},status={}", orderId, sign, status);
        if (status.equals("0")) {
            jsonObject.remove("status");
        }
        if ("1".equals(status)) {
            if (!StringUtils.isEmpty(orderId)) {

                try {

                    if (!lock(orderId)) {
                        log.error("haoyunUrl callback is lock");
                        return "error";
                    }

                    PlatMerOrder order = platMerOrderService.getByOrderId(orderId);
                    if (StringUtils.equals(order.getStat(), "2")) {
                        log.info("haoyunUrl callback order success");
                        return "success";
                    }

                    PlatMer byMerIdCache = platMerService.getByMerIdCache(order.getMerId());
                    if (byMerIdCache == null) {
                        log.info("haoyunUrl callback plat mer is empty not fund");
                        return "plat mer is empty not fund";
                    }

                    jsonObject.remove("sign");
                    SortedMap sortedMap = new TreeMap();
                    for (String key : jsonObject.keySet()) {
                        sortedMap.put(key, jsonObject.getString(key));
                    }
                    String s = convertUrlIsEmpty(sortedMap, "&", "=") + "key=" + byMerIdCache.getPrivateKey();
                    log.info("s {}", s);
                    String md5Str = SecureUtil.md5(s).toUpperCase();
                    log.info("sign {}", md5Str);

                    if (md5Str.equalsIgnoreCase(sign)) {

                        Double pay_money = jsonObject.getBigDecimal("amount").doubleValue();
                        /**
                         * 浮动金额
                         */
                        if (order.getAmount().doubleValue() == new BigDecimal(pay_money.doubleValue()).divide(new BigDecimal(100)).doubleValue()) {

                            int b = platMerOrderService.success(order);

                            if (b > 0) {

                                report(order);
                                log.info("haoyunUrl success");
                                return "SUCCESS";
                            } else {
                                log.error("haoyunUrl callback error");
                                return "error";
                            }

                        } else {
                            log.error("haoyunUrl callback amount is error order.getAmount(){} pay_money{}", order.getAmount(), pay_money);
                            return "amount is error";
                        }

                    } else {
                        log.error("haoyunUrl sign error");
                        return "sign error";
                    }

                } catch (RuntimeException ex) {
                    log.error("haoyunUrl notify EpayException", ex);
                    return "error" + ex.getMessage();
                } catch (Exception ex) {
                    log.error("haoyunUrl callback notify Exception", ex);
                    return "system ex ";
                } finally {
                    unlock(orderId);
                }
            } else {
                log.error("mnashangUrl callback plat order is error" + jsonObject.toJSONString());
                return "plat order status is error";
            }
        } else {
            log.error("mnashangUrl status is error" + jsonObject.toJSONString());
            return "plat order status is error";
        }
    }

        public String antengUrl(JSONObject jsonObject) {
            String orderId = jsonObject.getString("ordernumber");
            String status = jsonObject.getString("orderstatus");
            String sign = jsonObject.getString("sign");
            log.info(String.format("orderId=%s, status=%s, sign=%s", orderId, status, sign));

            if ("1".equals(status)) {

                if (!StringUtils.isEmpty(orderId)) {

                    try {

                        if (!lock(orderId)) {
                            log.error("hongYi is lock");
                            return "error";
                        }

                        PlatMerOrder order = platMerOrderService.getByOrderId(orderId);
                        if (StringUtils.equals(order.getStat(), "2")) {
                            log.info("hongyi success");
                            return "success";
                        }

                        PlatMer byMerIdCache = platMerService.getByMerIdCache(order.getMerId());
                        if (byMerIdCache == null) {
                            log.info("hongyi plat mer is empty not fund");
                            return "plat mer is empty not fund";
                        }

                        String s = "partner=" + jsonObject.getString("partner") + "&ordernumber=" + jsonObject.getString("ordernumber") +
                                "&orderstatus=" + status + "&paymoney=" + jsonObject.getString("paymoney") +
                                "&sysnumber=" + jsonObject.getString("sysnumber") + byMerIdCache.getPrivateKey();
                        String md5Str = SecureUtil.md5(s);
                        log.info("hongYi s " + s);
                        log.info("hongYi md5(s) " + md5Str);

                        if (md5Str.toLowerCase().equals(sign)) {

                            if (order.getAmount().doubleValue() == jsonObject.getDouble("paymoney")) {

                                int b = platMerOrderService.success(order);

                                if (b > 0) {
                                    report(order);
                                    log.info("hongyi callback success");
                                    return "ok";
                                } else {
                                    log.error("error");
                                    return "error";
                                }

                            } else {
                                log.error("amount is error");
                                return "amount is error";
                            }

                        } else {
                            log.error("sign error");
                            return "sign error";
                        }

                    } catch (RuntimeException ex) {
                        log.error("notify EpayException", ex);
                        return "error" + ex.getMessage();
                    } catch (Exception ex) {
                        log.error("notify Exception", ex);
                        return "system ex ";
                    } finally {
                        unlock(orderId);
                    }

                } else {
                    log.error("plat order id is empty" + orderId);
                    return "plat order id is empty";
                }

            } else {
                log.error("plat order is error" + jsonObject.toJSONString());
                return "plat order status is error";
            }
        }

    public String yeziUrl(JSONObject jsonObject) {
        return moqingUrl(jsonObject);
    }

    public String changfutongUrl(JSONObject jsonObject) {
        return jinxinUrl(jsonObject);
    }

    public String longfaUrl(JSONObject jsonObject) {
        return moqingUrl(jsonObject);
    }

    public String zongcaiUrl(JSONObject jsonObject) {
        String orderId = jsonObject.getString("order_no");
        String status = jsonObject.getString("trade_status");
        String sign = jsonObject.getString("sign");
        log.info(String.format("orderId=%s, status=%s, sign=%s", orderId, status, sign));

        if ("success".equals(status)) {

            if (!StringUtils.isEmpty(orderId)) {

                try {

                    if (!lock(orderId)) {
                        log.error("hongYi is lock");
                        return "error";
                    }

                    PlatMerOrder order = platMerOrderService.getByOrderId(orderId);
                    if (StringUtils.equals(order.getStat(), "2")) {
                        log.info("hongyi success");
                        return "success";
                    }

                    PlatMer byMerIdCache = platMerService.getByMerIdCache(order.getMerId());
                    if (byMerIdCache == null) {
                        log.info("hongyi plat mer is empty not fund");
                        return "plat mer is empty not fund";
                    }

                    jsonObject.remove("sign");
                    SortedMap sortedMap = new TreeMap();
                    for (String key : jsonObject.keySet()) {
                        if (!"null".equals(jsonObject.getString(key))) {
                            sortedMap.put(key, jsonObject.getString(key));
                        }
                    }
                    String s = convertUrl(sortedMap, "&", "=") + "&key=" + byMerIdCache.getPrivateKey();
                    log.info("s {}", s);
                    String md5Str = SecureUtil.md5(s);
                    log.info("sign {}", md5Str);

                    if (md5Str.equals(sign)) {

                        if (order.getAmount().doubleValue() == jsonObject.getDouble("order_amount")) {

                            int b = platMerOrderService.success(order);

                            if (b > 0) {
                                report(order);
                                log.info("hongyi callback success");
                                return "success";
                            } else {
                                log.error("error");
                                return "error";
                            }

                        } else {
                            log.error("amount is error");
                            return "amount is error";
                        }

                    } else {
                        log.error("sign error");
                        return "sign error";
                    }

                } catch (RuntimeException ex) {
                    log.error("notify EpayException", ex);
                    return "error" + ex.getMessage();
                } catch (Exception ex) {
                    log.error("notify Exception", ex);
                    return "system ex ";
                } finally {
                    unlock(orderId);
                }

            } else {
                log.error("plat order id is empty" + orderId);
                return "plat order id is empty";
            }

        } else {
            log.error("plat order is error" + jsonObject.toJSONString());
            return "plat order status is error";
        }
    }

    public String jinyuanUrl(JSONObject jsonObject) {
        String orderId = jsonObject.getString("orderid");
        String status = jsonObject.getString("opstate");
        String sign = jsonObject.getString("sign");
        log.info(String.format("orderId=%s, status=%s, sign=%s", orderId, status, sign));

        if ("0".equals(status)) {

            if (!StringUtils.isEmpty(orderId)) {

                try {

                    if (!lock(orderId)) {
                        log.error("hongYi is lock");
                        return "error";
                    }

                    PlatMerOrder order = platMerOrderService.getByOrderId(orderId);
                    if (StringUtils.equals(order.getStat(), "2")) {
                        log.info("hongyi success");
                        return "success";
                    }

                    PlatMer byMerIdCache = platMerService.getByMerIdCache(order.getMerId());
                    if (byMerIdCache == null) {
                        log.info("hongyi plat mer is empty not fund");
                        return "plat mer is empty not fund";
                    }

                    jsonObject.remove("sign");
                    SortedMap sortedMap = new TreeMap();
                    for (String key : jsonObject.keySet()) {
                        sortedMap.put(key, jsonObject.getString(key));
                    }
                    String s = convertUrl(sortedMap, "&", "=") + byMerIdCache.getPrivateKey();
                    log.info("s {}", s);
                    String md5Str = SecureUtil.md5(s).toLowerCase();
                    log.info("sign {}", md5Str);

                    if (md5Str.equals(sign)) {

                        if (order.getAmount().doubleValue() == jsonObject.getDouble("ovalue")) {

                            int b = platMerOrderService.success(order);

                            if (b > 0) {
                                report(order);
                                log.info("hongyi callback success");
                                return "OK";
                            } else {
                                log.error("error");
                                return "error";
                            }

                        } else {
                            log.error("amount is error");
                            return "amount is error";
                        }

                    } else {
                        log.error("sign error");
                        return "sign error";
                    }

                } catch (RuntimeException ex) {
                    log.error("notify EpayException", ex);
                    return "error" + ex.getMessage();
                } catch (Exception ex) {
                    log.error("notify Exception", ex);
                    return "system ex ";
                } finally {
                    unlock(orderId);
                }

            } else {
                log.error("plat order id is empty" + orderId);
                return "plat order id is empty";
            }

        } else {
            log.error("plat order is error" + jsonObject.toJSONString());
            return "plat order status is error";
        }
    }

    public String shuiguoUrl(JSONObject jsonObject) {
        return pilinUrl(jsonObject);
    }

    public String qianyifuUrl(JSONObject jsonObject) {
        return sljUrl(jsonObject);
    }


    public String yingfutongUrl(JSONObject jsonObject) {
        String orderId = jsonObject.getString("order_id");
        String status = jsonObject.getString("returncode");
        String sign = jsonObject.getString("sign");
        log.info(String.format("orderId=%s, status=%s, sign=%s", orderId, status, sign));

        if ("00".equals(status)) {

            if (!StringUtils.isEmpty(orderId)) {

                try {

                    if (!lock(orderId)) {
                        log.error("hongYi is lock");
                        return "error";
                    }

                    PlatMerOrder order = platMerOrderService.getByOrderId(orderId);
                    if (StringUtils.equals(order.getStat(), "2")) {
                        log.info("hongyi success");
                        return "success";
                    }

                    PlatMer byMerIdCache = platMerService.getByMerIdCache(order.getMerId());
                    if (byMerIdCache == null) {
                        log.info("hongyi plat mer is empty not fund");
                        return "plat mer is empty not fund";
                    }

                    jsonObject.remove("sign");
                    SortedMap sortedMap = new TreeMap();
                    for (String key : jsonObject.keySet()) {
                        sortedMap.put(key, jsonObject.getString(key));
                    }
                    String s = convertUrl(sortedMap, "&", "=") + "&token=" + byMerIdCache.getPrivateKey();
                    log.info("s {}", s);
                    String md5Str = SecureUtil.md5(s).toUpperCase();
                    log.info("sign {}", md5Str);

                    if (md5Str.equals(sign)) {

                        if (order.getAmount().doubleValue() == jsonObject.getDouble("amount_actual")) {

                            int b = platMerOrderService.success(order);

                            if (b > 0) {
                                report(order);
                                log.info("hongyi callback success");
                                return "success";
                            } else {
                                log.error("error");
                                return "error";
                            }

                        } else {
                            log.error("amount is error");
                            return "amount is error";
                        }

                    } else {
                        log.error("sign error");
                        return "sign error";
                    }

                } catch (RuntimeException ex) {
                    log.error("notify EpayException", ex);
                    return "error" + ex.getMessage();
                } catch (Exception ex) {
                    log.error("notify Exception", ex);
                    return "system ex ";
                } finally {
                    unlock(orderId);
                }

            } else {
                log.error("plat order id is empty" + orderId);
                return "plat order id is empty";
            }

        } else {
            log.error("plat order is error" + jsonObject.toJSONString());
            return "plat order status is error";
        }
    }

    public String bangshengUrl(JSONObject jsonObject) {
        return luoyaoUrl(jsonObject);
    }

    public String cftUrl(JSONObject jsonObject) {
        return jinxinUrl(jsonObject);
    }

    public String xiaodizhuUrl(JSONObject jsonObject) {
        return qianjinfuUrl(jsonObject);
    }

    public String xiaofeiyuUrl(JSONObject jsonObject) {
        return fcpayUrl(jsonObject);
    }

    public String jueqiUrl(JSONObject jsonObject) {
        return yinFuTong(jsonObject);
    }

    public String shuangshengUrl(JSONObject jsonObject) {
        String merchOrder = jsonObject.getString("orderNo");

        String status = jsonObject.getString("state");
        String sign = jsonObject.getString("sign");

        //message
        jsonObject.remove("sign");

        if (!status.equals("1")) {
            log.error("plat order is error" + jsonObject.toJSONString());
            return "plat order status is error";
        }


        if (StringUtils.isEmpty(merchOrder)) {

            log.error("plat order id is empty" + merchOrder);
            return "plat order id is empty";
        }

        try {
            if (!lock(merchOrder)) {
                return "error";
            }


            PlatMerOrder byOrderId = platMerOrderService.getByOrderId(merchOrder);

            if (StringUtils.equals(byOrderId.getStat(), "2")) {
                return "SUCCESS";
            }

            PlatMer byMerIdCache = platMerService.getByMerIdCache(byOrderId.getMerId());

            if (byMerIdCache == null) {
                return "plat mer is empty not fund";
            }


            String s = jsonObject.getString("state") + byMerIdCache.getMerKey() + jsonObject.getString("orderNo") + jsonObject.getString("amount") + byMerIdCache.getPrivateKey();
            log.error(" sign url error {}", s);
//            String sign = SecureUtil.md5(s +"&"+ byMerIdCache.getPrivateKey()).toLowerCase();
            log.error(" sign url error {}", s);
            if (!SecureUtil.md5(s).toLowerCase().equals(sign)) {
                return "sign error";
            }


            if (byOrderId.getAmount().doubleValue() != jsonObject.getDouble("amount")) {
                return "amount is  error";
            }

            int b = platMerOrderService.success(byOrderId);
            if (b > 0) {


                report(byOrderId);

                return "SUCCESS";
            }
            return "error";

        } catch (RuntimeException ex) {
            log.error("notify EpayException", ex);
            return "error" + ex.getMessage();
        } catch (Exception ex) {
            log.error("notify Exception", ex);
            return "system ex ";
        } finally {
            unlock(merchOrder);
        }    }

    public String hcUrl(JSONObject jsonObject) {
        String merchOrder = jsonObject.getString("orderNo");

        String status = jsonObject.getString("state");
        String sign = jsonObject.getString("sign");

        //message
        jsonObject.remove("sign");

        if (!status.equals("1")) {
            log.error("plat order is error" + jsonObject.toJSONString());
            return "plat order status is error";
        }


        if (StringUtils.isEmpty(merchOrder)) {

            log.error("plat order id is empty" + merchOrder);
            return "plat order id is empty";
        }

        try {
            if (!lock(merchOrder)) {
                return "error";
            }


            PlatMerOrder byOrderId = platMerOrderService.getByOrderId(merchOrder);

            if (StringUtils.equals(byOrderId.getStat(), "2")) {
                return "success";
            }

            PlatMer byMerIdCache = platMerService.getByMerIdCache(byOrderId.getMerId());

            if (byMerIdCache == null) {
                return "plat mer is empty not fund";
            }


            String s = jsonObject.getString("state") + byMerIdCache.getMerKey() + jsonObject.getString("orderNo") + jsonObject.getString("amount") + byMerIdCache.getPrivateKey();
            log.error(" sign url error {}", s);
//            String sign = SecureUtil.md5(s +"&"+ byMerIdCache.getPrivateKey()).toLowerCase();
            log.error(" sign url error {}", s);
            if (!SecureUtil.md5(s).toLowerCase().equals(sign)) {
                return "sign error";
            }


            if (byOrderId.getAmount().doubleValue() != jsonObject.getDouble("actualPayAmount")) {
                return "amount is  error";
            }

            int b = platMerOrderService.success(byOrderId);
            if (b > 0) {


                report(byOrderId);

                return "success";
            }
            return "error";

        } catch (RuntimeException ex) {
            log.error("notify EpayException", ex);
            return "error" + ex.getMessage();
        } catch (Exception ex) {
            log.error("notify Exception", ex);
            return "system ex ";
        } finally {
            unlock(merchOrder);
        }        }

    public String yunding2Url(JSONObject jsonObject) {
        return tbdfh5(jsonObject);
    }


    public String ziyouUrl(JSONObject jsonObject) {
        String merchOrder = jsonObject.getString("tradeNo");

        String status = jsonObject.getString("code");
        String sign = jsonObject.getString("sign");

        //message
        jsonObject.remove("sign");

        if (!status.equals("200")) {
            log.error("plat order is error" + jsonObject.toJSONString());
            return "plat order status is error";
        }


        if (StringUtils.isEmpty(merchOrder)) {

            log.error("plat order id is empty" + merchOrder);
            return "plat order id is empty";
        }

        try {
            if (!lock(merchOrder)) {
                return "error";
            }


            PlatMerOrder byOrderId = platMerOrderService.getByOrderId(merchOrder);

            if (StringUtils.equals(byOrderId.getStat(), "2")) {
                return "SUCCESS";
            }

            PlatMer byMerIdCache = platMerService.getByMerIdCache(byOrderId.getMerId());

            if (byMerIdCache == null) {
                return "plat mer is empty not fund";
            }


            jsonObject.remove("sign");
            SortedMap sortedMap = new TreeMap();
            for (String key : jsonObject.keySet()) {
                sortedMap.put(key, jsonObject.getString(key));
            }
            String s = convertUrl(sortedMap, "&", "=") + "&key=" + byMerIdCache.getPrivateKey();
            log.info("s {}", s);
            String md5Str = SecureUtil.md5(s).toUpperCase();
            log.info("sign {}", md5Str);

            if (!SecureUtil.md5(s).toLowerCase().equals(sign)) {
                return "sign error";
            }


            if (byOrderId.getAmount().doubleValue() != jsonObject.getDouble("orderAmt")) {
                return "amount is  error";
            }

            int b = platMerOrderService.success(byOrderId);
            if (b > 0) {


                report(byOrderId);

                return "success";
            }
            return "error";

        } catch (RuntimeException ex) {
            log.error("notify EpayException", ex);
            return "error" + ex.getMessage();
        } catch (Exception ex) {
            log.error("notify Exception", ex);
            return "system ex ";
        } finally {
            unlock(merchOrder);
        }        }

    public String lxUrl(JSONObject jsonObject) {
        return shuangshengUrl(jsonObject);
    }

    public String kaer2Url(JSONObject jsonObject) {
        String merchOrder = jsonObject.getString("orderNo");

        String status = jsonObject.getString("state");
        String sign = jsonObject.getString("sign");

        //message
        jsonObject.remove("sign");

        if (!status.equals("1")) {
            log.error("plat order is error" + jsonObject.toJSONString());
            return "plat order status is error";
        }


        if (StringUtils.isEmpty(merchOrder)) {

            log.error("plat order id is empty" + merchOrder);
            return "plat order id is empty";
        }

        try {
            if (!lock(merchOrder)) {
                return "error";
            }


            PlatMerOrder byOrderId = platMerOrderService.getByOrderId(merchOrder);

            if (StringUtils.equals(byOrderId.getStat(), "2")) {
                return "SUCCESS";
            }

            PlatMer byMerIdCache = platMerService.getByMerIdCache(byOrderId.getMerId());

            if (byMerIdCache == null) {
                return "plat mer is empty not fund";
            }


            String s = jsonObject.getString("state") + "&"+byMerIdCache.getMerKey() +"&"+
                    jsonObject.getString("orderNo") + "&"+ jsonObject.getString("amount") + "&"+
                    byMerIdCache.getPrivateKey();
            log.error(" sign url error {}", s);
//            String sign = SecureUtil.md5(s +"&"+ byMerIdCache.getPrivateKey()).toLowerCase();
            log.error(" sign url error {}", s);
            if (!SecureUtil.md5(s).toLowerCase().equals(sign)) {
                return "sign error";
            }


            if (byOrderId.getAmount().doubleValue() != jsonObject.getDouble("actualPayAmount")) {
                return "amount is  error";
            }

            int b = platMerOrderService.success(byOrderId);
            if (b > 0) {


                report(byOrderId);
                log.info("success");
                return "success";
            }
            return "error";

        } catch (RuntimeException ex) {
            log.error("notify EpayException", ex);
            return "error" + ex.getMessage();
        } catch (Exception ex) {
            log.error("notify Exception", ex);
            return "system ex ";
        } finally {
            unlock(merchOrder);
        }        }


    public String aUrl(JSONObject jsonObject) {
        return hongyiUrl(jsonObject);
    }


    public String daitouUrl(JSONObject jsonObject) {
        String merchOrder = jsonObject.getString("orderid");

        String status = jsonObject.getString("state");
        String sign = jsonObject.getString("key");

        //message
        jsonObject.remove("key");
//
//        if (!status.equals("1")) {
//            log.error("plat order is error" + jsonObject.toJSONString());
//            return "plat order status is error";
//        }


        if (StringUtils.isEmpty(merchOrder)) {

            log.error("plat order id is empty" + merchOrder);
            return "plat order id is empty";
        }

        try {
            if (!lock(merchOrder)) {
                return "error";
            }


            PlatMerOrder byOrderId = platMerOrderService.getByOrderId(merchOrder);

            if (StringUtils.equals(byOrderId.getStat(), "2")) {
                return "SUCCESS";
            }

            PlatMer byMerIdCache = platMerService.getByMerIdCache(byOrderId.getMerId());

            if (byMerIdCache == null) {
                return "plat mer is empty not fund";
            }
            jsonObject.put("token", byMerIdCache.getPrivateKey());

            Map<String, Object> sortedMap = new TreeMap();
            for (String key : jsonObject.keySet()) {
                sortedMap.put(key, jsonObject.getString(key));
            }

            StringBuilder stringBuilder = new StringBuilder();
            for (Map.Entry<String, Object> entry : sortedMap.entrySet()) {
                stringBuilder.append(entry.getValue());
            }

            String s = stringBuilder.toString();
            log.info("s {}", s);

            String md5Str = SecureUtil.md5(s).toLowerCase();
            log.info("sign {}", md5Str);

            if (!md5Str.equals(sign)) {
                return "sign error";
            }


            if (byOrderId.getAmount().doubleValue() != jsonObject.getDouble("price")) {
                return "amount is  error";
            }

            int b = platMerOrderService.success(byOrderId);
            if (b > 0) {


                report(byOrderId);
                log.info("200");
                return "200";
            }
            return "error";

        } catch (RuntimeException ex) {
            log.error("notify EpayException", ex);
            return "error" + ex.getMessage();
        } catch (Exception ex) {
            log.error("notify Exception", ex);
            return "system ex ";
        } finally {
            unlock(merchOrder);
        }
    }

    public String ysUrl(JSONObject jsonObject) {
        return dongyayihao(jsonObject);
    }

    public String huoxingUrl(JSONObject jsonObject) {
        log.info("huoxing {}", jsonObject);

        String merchOrder = jsonObject.getString("sh_order");


        String sign = jsonObject.getString("sign");

        String status = jsonObject.getString("status");

        if (!status.equals("success")) {
            log.error("plat order is error" + jsonObject.toJSONString());
            return "plat order status is error";
        }

        //message
        jsonObject.remove("sign");
        SortedMap sortedMap = new TreeMap();
        for (String key : jsonObject.keySet()) {

            sortedMap.put(key, jsonObject.getString(key));
        }


        if (StringUtils.isEmpty(merchOrder)) {

            log.error("plat order id is empty" + merchOrder);
            return "plat order id is empty";
        }

        try {
            if (!lock(merchOrder)) {
                return "error";
            }


            PlatMerOrder byOrderId = platMerOrderService.getByOrderId(merchOrder);

            if (StringUtils.equals(byOrderId.getStat(), "2")) {
                return "success";
            }

            PlatMer byMerIdCache = platMerService.getByMerIdCache(byOrderId.getMerId());

            if (byMerIdCache == null) {
                return "plat mer is empty not fund";
            }

            String s = convertUrl(sortedMap, "&", "=") + "&key=" + byMerIdCache.getPrivateKey();
//            String sign = SecureUtil.md5(s +"&"+ byMerIdCache.getPrivateKey()).toLowerCase();
            log.error(" sign url error {}", s);
            if (!SecureUtil.md5(s).toLowerCase().equals(sign)) {
                return "sign error";
            }


            if (byOrderId.getAmount().doubleValue() != jsonObject.getDouble("money")) {
                return "amount is  error";
            }

            int b = platMerOrderService.success(byOrderId);
            if (b > 0) {


                report(byOrderId);

                return "success";
            }
            return "error";

        } catch (RuntimeException ex) {
            log.error("notify EpayException", ex);
            return "error" + ex.getMessage();
        } catch (Exception ex) {
            log.error("notify Exception", ex);
            return "system ex ";
        } finally {
            unlock(merchOrder);
        }
    }

    public String openUrl(JSONObject jsonObject) {
        return huoxingUrl(jsonObject);
    }
    public String kkUrl(JSONObject jsonObject) {
        return huoxingUrl(jsonObject);
    }

    public String nanjiUrl(JSONObject jsonObject) {
        log.info("huoxing {}", jsonObject);

        String merchOrder = jsonObject.getString("orderid");


        String sign = jsonObject.getString("sign");

        String status = jsonObject.getString("status");

        if (!status.equals("1")) {
            log.error("plat order is error" + jsonObject.toJSONString());
            return "plat order status is error";
        }

        //message
        jsonObject.remove("sign");
        SortedMap sortedMap = new TreeMap();
        for (String key : jsonObject.keySet()) {
            sortedMap.put(key, jsonObject.getString(key));
        }


        if (StringUtils.isEmpty(merchOrder)) {

            log.error("plat order id is empty" + merchOrder);
            return "plat order id is empty";
        }

        try {
            if (!lock(merchOrder)) {
                return "error";
            }


            PlatMerOrder byOrderId = platMerOrderService.getByOrderId(merchOrder);

            if (StringUtils.equals(byOrderId.getStat(), "2")) {
                return "success";
            }

            PlatMer byMerIdCache = platMerService.getByMerIdCache(byOrderId.getMerId());

            if (byMerIdCache == null) {
                return "plat mer is empty not fund";
            }

            String s = convertUrlNotrim(sortedMap, "", "") + byMerIdCache.getPrivateKey();
            log.error("s list {}" ,s);
            MessageDigest md = MessageDigest.getInstance("SHA-1");


            md.update(s.getBytes());


            byte[] digest = md.digest();


            StringBuffer sb = new StringBuffer();


            for (byte b : digest) {


                sb.append(Integer.toString((b & 0xff) + 0x100, 16).substring(1));


            }

//            String sign = SecureUtil.md5(s +"&"+ byMerIdCache.getPrivateKey()).toLowerCase();
            log.error(" sign url error {} {} sb {}", s,sign,sb);
            if (!sb.toString().toUpperCase().equalsIgnoreCase(sign.toString())) {
                return "sign error";
            }


            if (byOrderId.getAmount().doubleValue() != jsonObject.getDouble("rmb")) {
                return "amount is  error";
            }

            int b = platMerOrderService.success(byOrderId);
            if (b > 0) {


                report(byOrderId);
                log.info("success");
                return "success";
            }
            return "error";

        } catch (RuntimeException ex) {
            log.error("notify EpayException", ex);
            return "error" + ex.getMessage();
        } catch (Exception ex) {
            log.error("notify Exception", ex);
            return "system ex ";
        } finally {
            unlock(merchOrder);
        }
    }
    public String leishenUrl(JSONObject jsonObject) {
        log.info("huoxing {}", jsonObject);

        String merchOrder = jsonObject.getString("outOrderId");


        String sign = jsonObject.getString("sign");

        String status = jsonObject.getString("partnerOrderStatus");

        if (!status.equals("SUCCESS")) {
            log.error("plat order is error" + jsonObject.toJSONString());
            return "plat order status is error";
        }

        //message
        jsonObject.remove("sign");
        SortedMap sortedMap = new TreeMap();
        for (String key : jsonObject.keySet()) {
            sortedMap.put(key, jsonObject.getString(key));
        }


        if (StringUtils.isEmpty(merchOrder)) {

            log.error("plat order id is empty" + merchOrder);
            return "plat order id is empty";
        }

        try {
            if (!lock(merchOrder)) {
                return "error";
            }


            PlatMerOrder byOrderId = platMerOrderService.getByOrderId(merchOrder);

            if (StringUtils.equals(byOrderId.getStat(), "2")) {
                return "success";
            }

            PlatMer byMerIdCache = platMerService.getByMerIdCache(byOrderId.getMerId());

            if (byMerIdCache == null) {
                return "plat mer is empty not fund";
            }

            String s = convertUrl(sortedMap, "&", "=") + byMerIdCache.getPrivateKey();
//            String sign = SecureUtil.md5(s +"&"+ byMerIdCache.getPrivateKey()).toLowerCase();
            log.error(" sign url error {}", s);
            if (!SecureUtil.md5(s).toUpperCase().equals(sign)) {
                return "sign error";
            }


            if (byOrderId.getAmount().doubleValue() != jsonObject.getDouble("amount")) {
                return "amount is  error";
            }

            int b = platMerOrderService.success(byOrderId);
            if (b > 0) {


                report(byOrderId);
                log.info("SUCCESS");
                return "SUCCESS";
            }
            return "error";

        } catch (RuntimeException ex) {
            log.error("notify EpayException", ex);
            return "error" + ex.getMessage();
        } catch (Exception ex) {
            log.error("notify Exception", ex);
            return "system ex ";
        } finally {
            unlock(merchOrder);
        }
    }

    public String yinshangfuUrl(JSONObject jsonObject) {
        log.info("huoxing {}", jsonObject);

        String merchOrder = jsonObject.getString("order_id");


        String sign = jsonObject.getString("sign");

        String status = jsonObject.getString("code");

        if (!status.equals("1")) {
            log.error("plat order is error" + jsonObject.toJSONString());
            return "plat order status is error";
        }

        //message
        jsonObject.remove("sign");
        SortedMap sortedMap = new TreeMap();
        for (String key : jsonObject.keySet()) {
            sortedMap.put(key, jsonObject.getString(key));
        }


        if (StringUtils.isEmpty(merchOrder)) {

            log.error("plat order id is empty" + merchOrder);
            return "plat order id is empty";
        }

        try {
            if (!lock(merchOrder)) {
                return "error";
            }


            PlatMerOrder byOrderId = platMerOrderService.getByOrderId(merchOrder);

            if (StringUtils.equals(byOrderId.getStat(), "2")) {
                return "success";
            }

            PlatMer byMerIdCache = platMerService.getByMerIdCache(byOrderId.getMerId());

            if (byMerIdCache == null) {
                return "plat mer is empty not fund";
            }

            String s = convertUrl(sortedMap, "&", "=") +"&key="+ byMerIdCache.getPrivateKey();
            log.info(" sign url sign {}", s);

            String mdsign = SecureUtil.md5(s).toUpperCase();
            log.info("sign " + mdsign);

            if (!mdsign.equals(sign)) {
                return "sign error";
            }


            if (byOrderId.getAmount().doubleValue() != jsonObject.getDouble("price")) {
                return "amount is  error";
            }

            int b = platMerOrderService.success(byOrderId);
            if (b > 0) {


                report(byOrderId);
                log.info("SUCCESS");
                return "SUCCESS";
            }
            return "error";

        } catch (RuntimeException ex) {
            log.error("notify EpayException", ex);
            return "error" + ex.getMessage();
        } catch (Exception ex) {
            log.error("notify Exception", ex);
            return "system ex ";
        } finally {
            unlock(merchOrder);
        }
    }

    public String shunfuUrl(JSONObject jsonObject) throws UnsupportedEncodingException {
        log.info("huoxing {}", jsonObject);

        String merchOrder = jsonObject.getString("orderNo");


        String sign = jsonObject.getString("sign");

        String status = jsonObject.getString("status");

        if (!status.equals("10000")) {
            log.error("plat order is error" + jsonObject.toJSONString());
            return "plat order status is error";
        }



        if (StringUtils.isEmpty(merchOrder)) {

            log.error("plat order id is empty" + merchOrder);
            return "plat order id is empty";
        }

        try {
            if (!lock(merchOrder)) {
                return "error";
            }


            PlatMerOrder byOrderId = platMerOrderService.getByOrderId(merchOrder);

            if (StringUtils.equals(byOrderId.getStat(), "2")) {
                return "success";
            }

            PlatMer byMerIdCache = platMerService.getByMerIdCache(byOrderId.getMerId());

            if (byMerIdCache == null) {
                return "plat mer is empty not fund";
            }

            //message
            jsonObject.remove("sign");
            SortedMap sortedMap = new TreeMap();
            for (String key : jsonObject.keySet()) {
                sortedMap.put(key, jsonObject.getString(key));
            }
            JSONObject jsonObject1 = new JSONObject(sortedMap);
            //排序 并 拼装成json字符串
            //paramsString 为排序好的字符串
            String str = convertUrlNotEmpty(sortedMap, "&", "=");
            log.info("s {}", str);

            log.info("public {}", byMerIdCache.getPublicKey());

            boolean flag = verifyByPublicKey(str.getBytes("UTF-8"), byMerIdCache.getPublicKey(), sign);
            log.info("flag {}", flag);

            if (!flag) {
                return "sign error";
            }


            if (byOrderId.getAmount().doubleValue() != jsonObject.getDouble("amount")) {
                return "amount is  error";
            }

            int b = platMerOrderService.success(byOrderId);
            if (b > 0) {


                report(byOrderId);
                log.info("SUCCESS");
                return "SUCCESS";
            }
            return "error";

        } catch (RuntimeException ex) {
            log.error("notify EpayException", ex);
            return "error" + ex.getMessage();
        } catch (Exception ex) {
            log.error("notify Exception", ex);
            return "system ex ";
        } finally {
            unlock(merchOrder);
        }
    }
    public static String signByPrivateKey(byte[] data, String privateKey) throws Exception {
        byte[] keyBytes = decryptBASE64(privateKey);
        PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(keyBytes);
        KeyFactory factory = KeyFactory.getInstance("RSA");
        PrivateKey priKey = factory.generatePrivate(keySpec);// 生成私钥
        // 用私钥对信息进行数字签名
        Signature signature = Signature.getInstance("SHA256withRSA");
        signature.initSign(priKey);
        signature.update(data);
        return encryptBASE64(signature.sign());

    }
    private static String encryptBASE64(byte[] data) {
        return new String(org.apache.commons.codec.binary.Base64.encodeBase64(data));
    }

    private static byte[] decryptBASE64(String data) {
        return org.apache.commons.codec.binary.Base64.decodeBase64(data);
    }
    public static boolean verifyByPublicKey(byte[] data, String publicKey, String sign) throws Exception {
        byte[] keyBytes = decryptBASE64(publicKey);
        X509EncodedKeySpec keySpec = new X509EncodedKeySpec(keyBytes);
        KeyFactory keyFactory = KeyFactory.getInstance("RSA");
        PublicKey pubKey = keyFactory.generatePublic(keySpec);
        Signature signature = Signature.getInstance("SHA256withRSA");
        signature.initVerify(pubKey);
        signature.update(data);
        return signature.verify(decryptBASE64(sign)); // 验证签名
    }

    public String wandeUrl(JSONObject jsonObject) {
        return binli(jsonObject);
    }



    public String xiaowuUrl(JSONObject jsonObject) {
        return binli(jsonObject);
    }

    public String ziyou1Url(JSONObject jsonObject) {
        return yinFuTong(jsonObject);
    }

    public String ggUrl(JSONObject jsonObject) throws UnsupportedEncodingException {
        log.info("huoxing {}", jsonObject);

        String merchOrder = jsonObject.getString("ordercode");


        String sign = jsonObject.getString("sign");

        String status = jsonObject.getString("orderstatus");

        if (!status.equals("2")) {
            log.error("plat order is error" + jsonObject.toJSONString());
            return "plat order status is error";
        }



        if (StringUtils.isEmpty(merchOrder)) {

            log.error("plat order id is empty" + merchOrder);
            return "plat order id is empty";
        }

        try {
            if (!lock(merchOrder)) {
                return "error";
            }


            PlatMerOrder byOrderId = platMerOrderService.getByOrderId(merchOrder);

            if (StringUtils.equals(byOrderId.getStat(), "2")) {
                return "success";
            }

            PlatMer byMerIdCache = platMerService.getByMerIdCache(byOrderId.getMerId());

            if (byMerIdCache == null) {
                return "plat mer is empty not fund";
            }

            //message
            //排序 并 拼装成json字符串
            //paramsString 为排序好的字符串
            String str = "custid=" + jsonObject.getString("custid") + "&" +
                    "ordercode="+ jsonObject.getString("ordercode") + "&" +
                    "amount=" + jsonObject.getString("amount") + "&" +
                    "backmemo=" + jsonObject.getString("backmemo") + "&" +
                    "key=" + byMerIdCache.getPrivateKey();
            log.info("s {}", str);


            String mdsign = SecureUtil.md5(str);
            log.info("sign " + mdsign);

            if (!mdsign.equals(sign)) {
                return "sign error";
            }

            if (byOrderId.getAmount().doubleValue() != new BigDecimal(jsonObject.getDouble("amount").doubleValue()).divide(new BigDecimal(100)).doubleValue()) {
                log.info("amount is error byOrderAmount {}", byOrderId.getAmount());
                return "amount is error";
            }

            int b = platMerOrderService.success(byOrderId);
            if (b > 0) {
                report(byOrderId);
                log.info("SUCCESS");
                return "SUCCESS";
            }
            return "error";

        } catch (RuntimeException ex) {
            log.error("notify EpayException", ex);
            return "error" + ex.getMessage();
        } catch (Exception ex) {
            log.error("notify Exception", ex);
            return "system ex ";
        } finally {
            unlock(merchOrder);
        }
    }

    public String lesumaUrl(JSONObject jsonObject) throws UnsupportedEncodingException {
        log.info("huoxing {}", jsonObject);

        String merchOrder = jsonObject.getString("OrderId");


        String sign = jsonObject.getString("Sign");

        String status = jsonObject.getString("Status");

        if (!status.equals("CODE_SUCCESS")) {
            log.error("plat order is error" + jsonObject.toJSONString());
            return "plat order status is error";
        }



        if (StringUtils.isEmpty(merchOrder)) {

            log.error("plat order id is empty" + merchOrder);
            return "plat order id is empty";
        }

        try {
            if (!lock(merchOrder)) {
                return "error";
            }


            PlatMerOrder byOrderId = platMerOrderService.getByOrderId(merchOrder);

            if (StringUtils.equals(byOrderId.getStat(), "2")) {
                return "success";
            }

            PlatMer byMerIdCache = platMerService.getByMerIdCache(byOrderId.getMerId());

            if (byMerIdCache == null) {
                return "plat mer is empty not fund";
            }

            //message
            jsonObject.remove("Sign");
            SortedMap sortedMap = new TreeMap();
            for (String key : jsonObject.keySet()) {
                sortedMap.put(key, jsonObject.getString(key));
            }
            JSONObject jsonObject1 = new JSONObject(sortedMap);
            //排序 并 拼装成json字符串
            //paramsString 为排序好的字符串
            String str = convertUrlNotEmpty(sortedMap, "&", "=") + "&key=" + byMerIdCache.getPrivateKey();
            String mdsign = SecureUtil.md5(str).toUpperCase();

            log.info("sign " + mdsign);

            if (!mdsign.equals(sign)) {
                return "sign error";
            }

            if (byOrderId.getAmount().doubleValue() != jsonObject.getDouble("Amount").doubleValue()) {
                log.info("amount is error byOrderAmount {}", byOrderId.getAmount());
                return "amount is error";
            }

            int b = platMerOrderService.success(byOrderId);
            if (b > 0) {
                report(byOrderId);
                log.info("OK");
                return "OK";
            }
            return "error";

        } catch (RuntimeException ex) {
            log.error("notify EpayException", ex);
            return "error" + ex.getMessage();
        } catch (Exception ex) {
            log.error("notify Exception", ex);
            return "system ex ";
        } finally {
            unlock(merchOrder);
        }
    }

    public String ruanyuUrl(JSONObject jsonObject) throws UnsupportedEncodingException {
        String merchOrder = jsonObject.getString("tradeNo");

        String status = jsonObject.getString("code");
        String sign = jsonObject.getString("sign");

        //message
        jsonObject.remove("sign");

        if (!status.equals("200")) {
            log.error("plat order is error" + jsonObject.toJSONString());
            return "plat order status is error";
        }


        if (StringUtils.isEmpty(merchOrder)) {

            log.error("plat order id is empty" + merchOrder);
            return "plat order id is empty";
        }

        try {
            if (!lock(merchOrder)) {
                return "error";
            }


            PlatMerOrder byOrderId = platMerOrderService.getByOrderId(merchOrder);

            if (StringUtils.equals(byOrderId.getStat(), "2")) {
                return "SUCCESS";
            }

            PlatMer byMerIdCache = platMerService.getByMerIdCache(byOrderId.getMerId());

            if (byMerIdCache == null) {
                return "plat mer is empty not fund";
            }


            jsonObject.remove("sign");
            SortedMap sortedMap = new TreeMap();
            for (String key : jsonObject.keySet()) {
                sortedMap.put(key, jsonObject.getString(key));
            }
            String s = convertUrl(sortedMap, "&", "=") + "&key=" + byMerIdCache.getPrivateKey();
            log.info("s {}", s);
            String md5Str = SecureUtil.md5(s).toUpperCase();
            log.info("sign {}", md5Str);

            if (!md5Str.equals(sign)) {
                return "sign error";
            }


            if (byOrderId.getAmount().doubleValue() != jsonObject.getDouble("orderAmt")) {
                return "amount is  error";
            }

            int b = platMerOrderService.success(byOrderId);
            if (b > 0) {


                report(byOrderId);

                return "success";
            }
            return "error";

        } catch (RuntimeException ex) {
            log.error("notify EpayException", ex);
            return "error" + ex.getMessage();
        } catch (Exception ex) {
            log.error("notify Exception", ex);
            return "system ex ";
        } finally {
            unlock(merchOrder);
        }            }

    public String baiyiUrl(JSONObject jsonObject) {
        log.info("kuaizhifu jsonObject " + jsonObject);
        String orderId = jsonObject.getJSONObject("data").getString("order_no");
        String status = jsonObject.getJSONObject("data").getString("status");
        String sign = jsonObject.getString("sign");
        log.info(String.format("dy orderId=%s, status=%s, sign=%s", orderId, status, sign));

        if ("1000".equals(status)) {

            if (!StringUtils.isEmpty(orderId)) {

                try {

                    if (!lock(orderId)) {
                        log.error("pilin is lock");
                        return "error";
                    }

                    PlatMerOrder order = platMerOrderService.getByOrderId(orderId);
                    if (StringUtils.equals(order.getStat(), "2")) {
                        return "success";
                    }

                    PlatMer byMerIdCache = platMerService.getByMerIdCache(order.getMerId());
                    if (byMerIdCache == null) {
                        return "plat mer is empty not fund";
                    }

                    jsonObject.remove("sign");
                    jsonObject.remove("sign_type");
                    Map<String, String> map = new TreeMap<>();
                    for (String key : jsonObject.keySet()) {


                        if (key.equals("data")) {
                            for (String datakey : jsonObject.getJSONObject("data").keySet()) {

                                map.put(datakey, jsonObject.getJSONObject("data").get(datakey).toString());
                            }
                        } else {
                            map.put(key, jsonObject.get(key).toString());
                        }
                    }
                    String s = convertUrl(map, "&", "=") + "&key=" + byMerIdCache.getPrivateKey();
                    String md5Str = SecureUtil.md5(s).toUpperCase();
                    log.info("s " + s);
                    log.info("md5(s) " + md5Str);

                    if (md5Str.equals(sign)) {

                        if (order.getAmount().doubleValue() == jsonObject.getJSONObject("data").getDouble("amount")) {

                            int b = platMerOrderService.success(order);

                            if (b > 0) {
                                report(order);
                                log.info("kuaizhifu SUCCESS");
                                return "SUCCESS";
                            } else {
                                log.error("error");
                                return "error";
                            }

                        } else {
                            log.error("amount is error");
                            return "amount is error";
                        }

                    } else {
                        log.error("sign error");
                        return "sign error";
                    }

                } catch (RuntimeException ex) {
                    log.error("notify EpayException", ex);
                    return "error" + ex.getMessage();
                } catch (Exception ex) {
                    log.error("notify Exception", ex);
                    return "system ex ";
                } finally {
                    unlock(orderId);
                }

            } else {
                log.error("plat order id is empty" + orderId);
                return "plat order id is empty";
            }

        } else {
            log.error("plat order is error" + jsonObject.toJSONString());
            return "plat order status is error";
        }

    }


    public String baobeiUrl(JSONObject jsonObject) {
        log.info("jsonObject {}", jsonObject);
        String merchOrder = jsonObject.getString("mchOrderNo");

        String status = jsonObject.getString("status");
        String sign = jsonObject.getString("sign");

        log.info("orderId{},sign{}", merchOrder, sign);

        //message
        jsonObject.remove("sign");

        if (!status.equals("2")) {
            log.error("plat order is error" + jsonObject.toJSONString());
            return "plat order status is error";
        }


        if (StringUtils.isEmpty(merchOrder)) {

            log.error("plat order id is empty" + merchOrder);
            return "plat order id is empty";
        }

        try {
            if (!lock(merchOrder)) {
                return "error";
            }


            PlatMerOrder byOrderId = platMerOrderService.getByOrderId(merchOrder);

            if (StringUtils.equals(byOrderId.getStat(), "2")) {
                return "SUCCESS";
            }

            PlatMer byMerIdCache = platMerService.getByMerIdCache(byOrderId.getMerId());

            if (byMerIdCache == null) {
                log.error("plat mer is empty not fund");
                return "plat mer is empty not fund";
            }


            jsonObject.remove("sign");
            SortedMap sortedMap = new TreeMap();
            for (String key : jsonObject.keySet()) {
                sortedMap.put(key, jsonObject.getString(key));
            }
            String s = convertUrl(sortedMap, "&", "=") + "&key=" + byMerIdCache.getPrivateKey();
            log.info("s {}", s);
            String md5Str = SecureUtil.md5(s).toUpperCase();
            log.info("sign {}", md5Str);

            if (!md5Str.equals(sign)) {
                return "sign error";
            }


            if (byOrderId.getAmount().doubleValue() != jsonObject.getBigDecimal("amount").divide(new BigDecimal(100)).doubleValue()) {
                log.info("amount {}", byOrderId.getAmount());
                return "amount is  error";
            }

            int b = platMerOrderService.success(byOrderId);
            if (b > 0) {


                report(byOrderId);
                log.info("success");

                return "success";
            }
            return "error";

        } catch (RuntimeException ex) {
            log.error("notify EpayException", ex);
            return "error" + ex.getMessage();
        } catch (Exception ex) {
            log.error("notify Exception", ex);
            return "system ex ";
        } finally {
            unlock(merchOrder);
        }            }


    public String huitengUrl(JSONObject jsonObject) {
        log.info("jsonObject {}", jsonObject);
        String merchOrder = jsonObject.getString("out_trade_no");

//        String status = jsonObject.getString("status");
        String sign = jsonObject.getString("sign");

        //message
        jsonObject.remove("sign");

//        if (!status.equals("2")) {
//            log.error("plat order is error" + jsonObject.toJSONString());
//            return "plat order status is error";
//        }


        if (StringUtils.isEmpty(merchOrder)) {

            log.error("plat order id is empty" + merchOrder);
            return "plat order id is empty";
        }

        try {
            if (!lock(merchOrder)) {
                return "error";
            }


            PlatMerOrder byOrderId = platMerOrderService.getByOrderId(merchOrder);

            if (StringUtils.equals(byOrderId.getStat(), "2")) {
                return "SUCCESS";
            }

            PlatMer byMerIdCache = platMerService.getByMerIdCache(byOrderId.getMerId());

            if (byMerIdCache == null) {
                return "plat mer is empty not fund";
            }

            Map<String, Object> sortedMap = new TreeMap<>();
            sortedMap.put("mch_id", jsonObject.get("mch_id"));
            sortedMap.put("out_trade_no", jsonObject.get("out_trade_no"));
            sortedMap.put("order_no", jsonObject.get("order_no"));
            sortedMap.put("pay_time", jsonObject.get("pay_time"));
            sortedMap.put("timestamp", jsonObject.get("timestamp"));
            sortedMap.put("total_fee", jsonObject.get("total_fee"));
            sortedMap.put("mch_secret", byMerIdCache.getPrivateKey());


            String s = convertUrlNotEmpty(sortedMap, "&", "=");
            log.info("s {}", s);
            String md5Str = SecureUtil.md5(s).toUpperCase();
            log.info("sign {}", md5Str);

            if (!md5Str.equals(sign)) {
                return "sign error";
            }


            if (byOrderId.getAmount().doubleValue() != jsonObject.getDouble("total_fee")) {
                log.info("amount {}", byOrderId.getAmount());
                return "amount is  error";
            }

            int b = platMerOrderService.success(byOrderId);
            if (b > 0) {


                report(byOrderId);
                log.info("success");

                return "success";
            }
            return "error";

        } catch (RuntimeException ex) {
            log.error("notify EpayException", ex);
            return "error" + ex.getMessage();
        } catch (Exception ex) {
            log.error("notify Exception", ex);
            return "system ex ";
        } finally {
            unlock(merchOrder);
        }            }

    public String guiguUrl(JSONObject jsonObject) {
        log.info("jsonObject {}", jsonObject);
        String merchOrder = jsonObject.getString("merchantorderid");

        String status = jsonObject.getString("status");
        String sign = jsonObject.getString("sign");

        //message
        jsonObject.remove("sign");

        if (!status.equals("2")) {
            log.error("plat order is error" + jsonObject.toJSONString());
            return "plat order status is error";
        }

        if (StringUtils.isEmpty(merchOrder)) {

            log.error("plat order id is empty" + merchOrder);
            return "plat order id is empty";
        }

        try {
            if (!lock(merchOrder)) {
                return "error";
            }

            PlatMerOrder byOrderId = platMerOrderService.getByOrderId(merchOrder);

            if (StringUtils.equals(byOrderId.getStat(), "2")) {
                return "SUCCESS";
            }

            PlatMer byMerIdCache = platMerService.getByMerIdCache(byOrderId.getMerId());

            if (byMerIdCache == null) {
                return "plat mer is empty not fund";
            }

            jsonObject.remove("sign");
            SortedMap sortedMap = new TreeMap();
            for (String key : jsonObject.keySet()) {
                sortedMap.put(key, jsonObject.getString(key));
            }
            String s = convertUrl(sortedMap, "&", "=") + "&key=" + byMerIdCache.getPrivateKey();
            log.info("s {}", s);
            String md5Str = SecureUtil.md5(s);
            log.info("sign {}", md5Str);
            if (!md5Str.equals(sign)) {
                return "sign error";
            }

            if (byOrderId.getAmount().doubleValue() != jsonObject.getDouble("applyamount")) {
                log.info("amount {}", byOrderId.getAmount());
                return "amount is  error";
            }

            int b = platMerOrderService.success(byOrderId);
            if (b > 0) {
                report(byOrderId);
                log.info("success");
                return "success";
            }
            return "error";
        } catch (RuntimeException ex) {
            log.error("notify EpayException", ex);
            return "error" + ex.getMessage();
        } catch (Exception ex) {
            log.error("notify Exception", ex);
            return "system ex ";
        } finally {
            unlock(merchOrder);
        }            }

    public String ifUrl(JSONObject jsonObject) {
        log.info("wykkt callback jsonObject " + jsonObject);
        String orderId = jsonObject.getString("orderRemark");
        String status = jsonObject.getString("state");
        String sign = jsonObject.getString("hmac");
        log.info(String.format("wykkt callback orderId=%s, status=%s, sign=%s", orderId, status, sign));

        if ("3".equals(status)) {

            if (!StringUtils.isEmpty(orderId)) {

                try {

                    if (!lock(orderId)) {
                        log.error("wykkt callback is lock");
                        return "error";
                    }

                    PlatMerOrder order = platMerOrderService.getByOrderId(orderId);
                    if (StringUtils.equals(order.getStat(), "2")) {
                        log.info("wykkt callback order success");
                        return "success";
                    }

                    PlatMer byMerIdCache = platMerService.getByMerIdCache(order.getMerId());
                    if (byMerIdCache == null) {
                        log.info("wykkt callback plat mer is empty not fund");
                        return "plat mer is empty not fund";
                    }

                    StringBuilder s = new StringBuilder("");
                    s.append(jsonObject.get("id")).append(byMerIdCache.getPrivateKey()).append(jsonObject.getString("orderAmount")).append(jsonObject.getString("orderRemark")).append(jsonObject.getString("state"))
                            .append(jsonObject.getString("type")).append(jsonObject.getDate("updateTime").getTime()).append(jsonObject.getString("userId"));

                    String md5Str = SecureUtil.md5(s.toString()).toUpperCase();

                    log.info("wykkt s " + s);
                    log.info("wykkt md5(s) " + md5Str);

                    if (md5Str.equals(sign)) {

                        int b = platMerOrderService.success(order);

                        if (b > 0) {
                            report(order);
                            log.info("wykkt SUCCESS");
                            return "SUCCESS";
                        } else {
                            log.error("wykkt callback error");
                            return "error";
                        }

                    } else {
                        log.error("wykkt callback sign error");
                        return "sign error";
                    }

                } catch (RuntimeException ex) {
                    log.error("wykkt callback notify EpayException", ex);
                    return "error" + ex.getMessage();
                } catch (Exception ex) {
                    log.error("wykkt callback notify Exception", ex);
                    return "system ex ";
                } finally {
                    unlock(orderId);
                }

            } else {
                log.error("wykkt callback plat order id is empty" + orderId);
                return "plat order id is empty";
            }

        } else {
            log.error("wykkt callback plat order is error" + jsonObject.toJSONString());
            return "plat order status is error";
        }
    }

    public String quzhifuPay(JSONObject jsonObject) {
        return XGPay(jsonObject);

    }

    public String yiliaoma(JSONObject jsonObject) {
        String merchOrder = jsonObject.getString("orderno");
        String returncode = jsonObject.getString("code");
        String sign = jsonObject.getString("signature");
        jsonObject.remove("signature");
        log.error(" order id " + merchOrder);
        SortedMap sortedMap = new TreeMap();
        for (String key : jsonObject.keySet()) {
            sortedMap.put(key, jsonObject.getString(key));
        }

        if (!returncode.equals("11")) {
            log.error("plat order is error" + jsonObject.toJSONString());
            return "plat order is error";
        }
        if (StringUtils.isEmpty(merchOrder)) {
            log.error("plat order id is empty" + merchOrder);
            return "plat order id is empty";
        }
        try {
            if (!lock(merchOrder)) {
                return "error";
            }
            PlatMerOrder byOrderId = platMerOrderService.getByOrderId(merchOrder);
            if (StringUtils.equals(byOrderId.getStat(), "2")) {
                return "success";
            }
            PlatMer byMerIdCache = platMerService.getByMerIdCache(byOrderId.getMerId());
            if (byMerIdCache == null) {
                return "plat mer is empty not fund";
            }
            String s = convertUrl(sortedMap, "&", "=");

            log.error(" sign url " + s);
            if (!SecureUtil.md5(s + "&key=" + byMerIdCache.getPrivateKey()).toUpperCase().equals(sign)) {
                return "sign error";
            }
            if (byOrderId.getAmount().doubleValue() !=( jsonObject.getBigDecimal("transamt").divide(new BigDecimal(100)).doubleValue())) {
                return "amount is  error";
            }
            int b = platMerOrderService.success(byOrderId);
            if (b > 0) {
                report(byOrderId);
                log.info("success");
                return "success";
            }
            return "error";

        } catch (RuntimeException ex) {
            log.error("notify EpayException", ex);
            return "error" + ex.getMessage();
        } catch (Exception ex) {
            log.error("notify Exception", ex);
            return "system ex ";
        } finally {
            unlock(merchOrder);
        }
    }

    public String huabaoUrl(JSONObject jsonObject) {
        return jinxinUrl(jsonObject);
    }

    public String dingshengUrl(JSONObject jsonObject) {
        return yinFuTong(jsonObject);
    }

    public String chaofanUrl(JSONObject jsonObject) {
        return yinFuTong(jsonObject);
    }

    public String dmUrl(JSONObject jsonObject) {
        return yinFuTong(jsonObject);
    }

    public String youyifuUrl(JSONObject jsonObject) {
        String merchOrder = jsonObject.getString("orderNo");
        String returncode = jsonObject.getString("payResult");
        String sign = jsonObject.getString("sign");
        jsonObject.remove("sign");
        log.error(" order id " + merchOrder);
        SortedMap sortedMap = new TreeMap();
        for (String key : jsonObject.keySet()) {
            sortedMap.put(key, jsonObject.getString(key));
        }

        if (!returncode.equals("8")) {
            log.error("plat order is error" + jsonObject.toJSONString());
            return "plat order is error";
        }
        if (StringUtils.isEmpty(merchOrder)) {
            log.error("plat order id is empty" + merchOrder);
            return "plat order id is empty";
        }
        try {
            if (!lock(merchOrder)) {
                return "error";
            }
            PlatMerOrder byOrderId = platMerOrderService.getByOrderId(merchOrder);
            if (StringUtils.equals(byOrderId.getStat(), "2")) {
                return "success";
            }
            PlatMer byMerIdCache = platMerService.getByMerIdCache(byOrderId.getMerId());
            if (byMerIdCache == null) {
                return "plat mer is empty not fund";
            }
            String s = convertUrl(sortedMap, "&", "=");

            log.error(" sign url " + s);
            if (!SecureUtil.md5(s + byMerIdCache.getPrivateKey()).toUpperCase().equals(sign)) {
                return "sign error";
            }
            if (byOrderId.getAmount().doubleValue() != jsonObject.getBigDecimal("amount").doubleValue()) {
                return "amount is  error";
            }
            int b = platMerOrderService.success(byOrderId);
            if (b > 0) {
                report(byOrderId);
                log.info("success");
                return "success";
            }
            return "error";

        } catch (RuntimeException ex) {
            log.error("notify EpayException", ex);
            return "error" + ex.getMessage();
        } catch (Exception ex) {
            log.error("notify Excpfpayeption", ex);
            return "system ex ";
        } finally {
            unlock(merchOrder);
        }
    }

    public String wangcaiUrl(JSONObject jsonObject) {
        return baichuanUrl(jsonObject);
    }

    public String longtengUrl(JSONObject jsonObject) {
        return yinFuTong(jsonObject);

    }

    public String longfuUrl(JSONObject jsonObject) {
        return xingguan(jsonObject);
    }

    public String liuyiPay(JSONObject jsonObject) {
        return xiaocaoPay(jsonObject);
    }

    public String jinxiUrl(JSONObject jsonObject) {
        return aqiang(jsonObject);
    }

    public String huojianUrl(JSONObject jsonObject) {
        return binli(jsonObject);
    }

    public String kaertaobaoUrl(JSONObject jsonObject) {
        String merchOrder = jsonObject.getString("out_order_no");
//        String returncode = jsonObject.getString("payResult");
        String sign = jsonObject.getString("sign");
        log.error(" order id " + merchOrder);
        SortedMap sortedMap = new TreeMap();
        for (String key : jsonObject.keySet()) {
            sortedMap.put(key, jsonObject.getString(key));
        }

//        if (!returncode.equals("8")) {
//            log.error("plat order is error" + jsonObject.toJSONString());
//            return "plat order is error";
//        }
        if (StringUtils.isEmpty(merchOrder)) {
            log.error("plat order id is empty" + merchOrder);
            return "plat order id is empty";
        }
        try {
            if (!lock(merchOrder)) {
                return "error";
            }
            PlatMerOrder byOrderId = platMerOrderService.getByOrderId(merchOrder);
            if (StringUtils.equals(byOrderId.getStat(), "2")) {
                return "success";
            }
            PlatMer byMerIdCache = platMerService.getByMerIdCache(byOrderId.getMerId());
            if (byMerIdCache == null) {
                return "plat mer is empty not fund";
            }
            String s = jsonObject.getString("appId") + "^" + jsonObject.getString("order_no") + "^" +
                    jsonObject.getString("out_order_no") + "^" + jsonObject.getString("trade_time") +
                    "^" + byMerIdCache.getPrivateKey();

            log.error(" sign url " + s);
            String md5s = SecureUtil.md5(s);
            if (!md5s.equals(sign)) {
                log.error("sign error {}",md5s );
                return "sign error";
            }
            if (byOrderId.getAmount().doubleValue() != jsonObject.getBigDecimal("trade_money").doubleValue()) {
                return "amount is  error";
            }
            int b = platMerOrderService.success(byOrderId);
            if (b > 0) {
                report(byOrderId);
                log.info("success");
                return "success";
            }
            return "error";

        } catch (RuntimeException ex) {
            log.error("notify EpayException", ex);
            return "error" + ex.getMessage();
        } catch (Exception ex) {
            log.error("notify Excpfpayeption", ex);
            return "system ex ";
        } finally {
            unlock(merchOrder);
        }
    }

    public String zhuanqianUrl(JSONObject jsonObject) {
        String merchOrder = jsonObject.getString("out_order_no");
//        String returncode = jsonObject.getString("payResult");
        String sign = jsonObject.getString("sign");
        log.error(" order id " + merchOrder);
        SortedMap sortedMap = new TreeMap();
        for (String key : jsonObject.keySet()) {
            sortedMap.put(key, jsonObject.getString(key));
        }

//        if (!returncode.equals("8")) {
//            log.error("plat order is error" + jsonObject.toJSONString());
//            return "plat order is error";
//        }
        if (StringUtils.isEmpty(merchOrder)) {
            log.error("plat order id is empty" + merchOrder);
            return "plat order id is empty";
        }
        try {
            if (!lock(merchOrder)) {
                return "error";
            }
            PlatMerOrder byOrderId = platMerOrderService.getByOrderId(merchOrder);
            if (StringUtils.equals(byOrderId.getStat(), "2")) {
                return "success";
            }
            PlatMer byMerIdCache = platMerService.getByMerIdCache(byOrderId.getMerId());
            if (byMerIdCache == null) {
                return "plat mer is empty not fund";
            }
            String s = jsonObject.getString("appId") + "^" + jsonObject.getString("order_no") + "^" +
                    jsonObject.getString("out_order_no") + "^" + jsonObject.getString("trade_time") +
                    "^" + byMerIdCache.getPrivateKey();

            log.error(" sign url " + s);
            String md5s = SecureUtil.md5(s);
            if (!md5s.equals(sign)) {
                log.error("sign error {}",md5s );
                return "sign error";
            }
            if (byOrderId.getAmount().doubleValue() != jsonObject.getBigDecimal("trade_money").doubleValue()) {
                return "amount is  error";
            }
            int b = platMerOrderService.success(byOrderId);
            if (b > 0) {
                report(byOrderId);
                log.info("success");
                return "success";
            }
            return "error";

        } catch (RuntimeException ex) {
            log.error("notify EpayException", ex);
            return "error" + ex.getMessage();
        } catch (Exception ex) {
            log.error("notify Excpfpayeption", ex);
            return "system ex ";
        } finally {
            unlock(merchOrder);
        }


        }

    public String shiliuUrl(JSONObject jsonObject) {
        return pilinUrl(jsonObject);
    }

    public String congzhongUrl(JSONObject jsonObject) {
        return dingshunUrl(jsonObject);
    }

    public String huitongUrl(JSONObject jsonObject) {
        return yinFuTong(jsonObject);
    }

    public String dongyaziyingUrl(JSONObject jsonObject) {


        return yinFuTong(jsonObject);
    }

    public String chengzi2Url(JSONObject jsonObject) {
        return yuxinUrl(jsonObject);
    }
    public String kcUrl(JSONObject jsonObject) {
        return yuxinUrl(jsonObject);
    }

    public String changjiangdingshunUrl(JSONObject jsonObject) {
        log.info("pilin jsonObject " + jsonObject);
        String orderId = jsonObject.getString("out_sn");
        String status = jsonObject.getString("trade_status");
        String sign = jsonObject.getString("sign");
        log.info(String.format("orderId=%s, status=%s, sign=%s", orderId, status, sign));

        if ("TRADE_SUCCESS".equals(status)) {

            if (!StringUtils.isEmpty(orderId)) {

                try {

                    if (!lock(orderId)) {
                        log.error("pilin is lock");
                        return "error";
                    }

                    PlatMerOrder order = platMerOrderService.getByOrderId(orderId);
                    if (StringUtils.equals(order.getStat(), "2")) {
                        return "success";
                    }

                    PlatMer byMerIdCache = platMerService.getByMerIdCache(order.getMerId());
                    if (byMerIdCache == null) {
                        return "plat mer is empty not fund";
                    }

                    jsonObject.remove("sign");
                    Map<String, String> map = new TreeMap<>();
                    for (String key : jsonObject.keySet()) {
                            map.put(key, jsonObject.get(key).toString());
                    }
                    String s = convertUrl(map, "&", "=") + "&key=" + byMerIdCache.getPrivateKey();
                    String md5Str = SecureUtil.md5(s).toUpperCase();
                    log.info("s " + s);
                    log.info("md5(s) " + md5Str);

                    if (md5Str.equals(sign)) {

                        if (order.getAmount().doubleValue() == jsonObject.getDouble("money")) {

                            int b = platMerOrderService.success(order);

                            if (b > 0) {
                                report(order);
                                log.info("success");
                                return "success";
                            } else {
                                log.error("error");
                                return "error";
                            }

                        } else {
                            log.error("amount is error");
                            return "amount is error";
                        }

                    } else {
                        log.error("sign error");
                        return "sign error";
                    }

                } catch (RuntimeException ex) {
                    log.error("notify EpayException", ex);
                    return "error" + ex.getMessage();
                } catch (Exception ex) {
                    log.error("notify Exception", ex);
                    return "system ex ";
                } finally {
                    unlock(orderId);
                }

            } else {
                log.error("plat order id is empty" + orderId);
                return "plat order id is empty";
            }

        } else {
            log.error("plat order is error" + jsonObject.toJSONString());
            return "plat order status is error";
        }

    }

    public String yuxinUrl(JSONObject jsonObject) {
        String merchOrder = jsonObject.getString("order_id");
//        String returncode = jsonObject.getString("payResult");
        String sign = jsonObject.getString("sign");
        log.error(" order id " + merchOrder);
        SortedMap sortedMap = new TreeMap();
        for (String key : jsonObject.keySet()) {
            sortedMap.put(key, jsonObject.getString(key));
        }

//        if (!returncode.equals("8")) {
//            log.error("plat order is error" + jsonObject.toJSONString());
//            return "plat order is error";
//        }
        if (StringUtils.isEmpty(merchOrder)) {
            log.error("plat order id is empty" + merchOrder);
            return "plat order id is empty";
        }
        try {
            if (!lock(merchOrder)) {
                return "error";
            }
            PlatMerOrder byOrderId = platMerOrderService.getByOrderId(merchOrder);
            if (StringUtils.equals(byOrderId.getStat(), "2")) {
                return "success";
            }
            PlatMer byMerIdCache = platMerService.getByMerIdCache(byOrderId.getMerId());
            if (byMerIdCache == null) {
                return "plat mer is empty not fund";
            }
            StringBuilder sb = new StringBuilder();
            jsonObject.remove("sign");
            Map<String, String> map = new LinkedHashMap<>();
            for (String key : jsonObject.keySet()) {
                sb.append(map.get(key));
            }

            String s = sb.append(byMerIdCache.getPrivateKey()).toString();
            String sha1Sign = this.encode(s);

            log.error(" sign url " + s);
            String md5s = SecureUtil.md5(s);
            if (!sha1Sign.equals(sign)) {
                log.error("sign error {}",md5s );
                return "sign error";
            }
            if (byOrderId.getAmount().doubleValue() != jsonObject.getBigDecimal("trade_money").doubleValue()) {
                return "amount is  error";
            }
            int b = platMerOrderService.success(byOrderId);
            if (b > 0) {
                report(byOrderId);
                log.info("success");
                return "success";
            }
            return "error";

        } catch (RuntimeException ex) {
            log.error("notify EpayException", ex);
            return "error" + ex.getMessage();
        } catch (Exception ex) {
            log.error("notify Excpfpayeption", ex);
            return "system ex ";
        } finally {
            unlock(merchOrder);
        }


    }
    public String uu898(JSONObject jsonObject) {
        String merchOrder = jsonObject.getString("orderId");
//        String returncode = jsonObject.getString("payResult");

//        if (!returncode.equals("8")) {
//            log.error("plat order is error" + jsonObject.toJSONString());
//            return "plat order is error";
//        }
        if (StringUtils.isEmpty(merchOrder)) {
            log.error("plat order id is empty" + merchOrder);
            return "plat order id is empty";
        }
        try {
            if (!lock(merchOrder)) {
                return "error";
            }
            PlatMerOrder byOrderId = platMerOrderService.getByOrderId(merchOrder);
            if (StringUtils.equals(byOrderId.getStat(), "2")) {
                return "success";
            }

            if (byOrderId.getAmount().doubleValue() != jsonObject.getBigDecimal("amount").doubleValue()) {
                return "amount is  error";
            }
            int b = platMerOrderService.success(byOrderId);
            if (b > 0) {
                report(byOrderId);
                log.info("success");
                return "success";
            }
            return "error";

        } catch (RuntimeException ex) {
            log.error("notify EpayException", ex);
            return "error" + ex.getMessage();
        } catch (Exception ex) {
            log.error("notify Excpfpayeption", ex);
            return "system ex ";
        } finally {
            unlock(merchOrder);
        }


    }


    private static final char[] HEX_DIGITS = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd',
            'e', 'f' };

    /**
     * Takes the raw bytes from the digest and formats them correct.
     *
     * @param bytes
     *            the raw bytes from the digest.
     * @return the formatted bytes.
     */
    private static String getFormattedText(byte[] bytes) {
        int len = bytes.length;
        StringBuilder buf = new StringBuilder(len * 2);
        // 把密文转换成十六进制的字符串形式
        for (int j = 0; j < len; j++) {
            buf.append(HEX_DIGITS[(bytes[j] >> 4) & 0x0f]);
            buf.append(HEX_DIGITS[bytes[j] & 0x0f]);
        }
        return buf.toString();
    }

    public static String encode(String str) {
        if (str == null) {
            return null;
        }
        try {
            MessageDigest messageDigest = MessageDigest.getInstance("SHA1");
            messageDigest.update(str.getBytes());
            return getFormattedText(messageDigest.digest());
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    public String subaUrl(JSONObject jsonObject) {
        return aqiang(jsonObject);
    }

    public String jfUrl(JSONObject jsonObject) {
        return yinFuTong(jsonObject);
    }

    public String kaer3Url(JSONObject jsonObject) {
        return aqiang(jsonObject);
    }


    public String kupaoUrl(JSONObject jsonObject) {
        String merchOrder = jsonObject.getString("merOrderNo");
        String returncode = jsonObject.getString("respCode");
        String sign = jsonObject.getString("signature");
        log.error(" order id " + merchOrder);
        SortedMap sortedMap = new TreeMap();
        for (String key : jsonObject.keySet()) {
            sortedMap.put(key, jsonObject.getString(key));
        }

        if (!returncode.equals("0000")) {
            log.error("plat order is error" + jsonObject.toJSONString());
            return "plat order is error";
        }
        if (StringUtils.isEmpty(merchOrder)) {
            log.error("plat order id is empty" + merchOrder);
            return "plat order id is empty";
        }
        try {
            if (!lock(merchOrder)) {
                return "error";
            }
            PlatMerOrder byOrderId = platMerOrderService.getByOrderId(merchOrder);
            if (StringUtils.equals(byOrderId.getStat(), "2")) {
                return "success";
            }
            PlatMer byMerIdCache = platMerService.getByMerIdCache(byOrderId.getMerId());
            if (byMerIdCache == null) {
                return "plat mer is empty not fund";
            }
            StringBuilder sb = new StringBuilder();
            jsonObject.remove("signature");
            Map<String, Object> map = new TreeMap<>();
            for (String key : jsonObject.keySet()) {
                map.put(key, jsonObject.get(key));
            }
            String s= convertUrlNotEmpty(map, "&", "=") + byMerIdCache.getPrivateKey();
            String sha1Sign = SecureUtil.md5(s).toLowerCase();

            log.error(" sign url " + s);
            String md5s = SecureUtil.md5(s);
            if (!sha1Sign.equals(sign)) {
                log.error("sign error {}",md5s );
                return "sign error";
            }
            if (byOrderId.getAmount().doubleValue() != jsonObject.getBigDecimal("actualPayAmt").doubleValue()) {
                return "amount is  error";
            }
            int b = platMerOrderService.success(byOrderId);
            if (b > 0) {
                report(byOrderId);
                log.info("SUCCESS");
                return "SUCCESS";
            }
            return "error";

        } catch (RuntimeException ex) {
            log.error("notify EpayException", ex);
            return "error" + ex.getMessage();
        } catch (Exception ex) {
            log.error("notify Excpfpayeption", ex);
            return "system ex ";
        } finally {
            unlock(merchOrder);
        }


    }

    public String huiteng2Url(JSONObject jsonObject) {
        return yinFuTong(jsonObject);
    }

    public String guangsuUrl(JSONObject jsonObject) {
        return huoxingUrl(jsonObject);
    }

    public String miaofuUrl(JSONObject jsonObject) {
        log.info("jinxin callback jsonObject " + jsonObject);
        String orderId = jsonObject.getString("mchOrderNo");
        String status = jsonObject.getString("status");
        String sign = jsonObject.getString("sign");
        log.info(String.format("jinxin callback orderId=%s, status=%s, sign=%s", orderId, status, sign));

        if ("2".equals(status)) {

            if (!StringUtils.isEmpty(orderId)) {

                try {

                    if (!lock(orderId)) {
                        log.error("jinxin callback is lock");
                        return "error";
                    }

                    PlatMerOrder order = platMerOrderService.getByOrderId(orderId);
                    if (StringUtils.equals(order.getStat(), "2")) {
                        log.info("jinxin callback order success");
                        return "success";
                    }

                    PlatMer byMerIdCache = platMerService.getByMerIdCache(order.getMerId());
                    if (byMerIdCache == null) {
                        log.info("jinxin callback plat mer is empty not fund");
                        return "plat mer is empty not fund";
                    }

                    jsonObject.remove("sign");
                    SortedMap sortedMap = new TreeMap();
                    for (String key : jsonObject.keySet()) {
                        sortedMap.put(key, jsonObject.getString(key));
                    }
                    String s = convertUrlNotEmpty(sortedMap, "&", "=") + "&key=" + byMerIdCache.getPrivateKey();
                    String md5Str = SecureUtil.md5(s).toUpperCase();

                    log.info("hongYi s " + s);
                    log.info("hongYi md5(s) " + md5Str);

                    if (md5Str.equals(sign)) {

                        if (order.getAmount().doubleValue() == (jsonObject.getDouble("amount") / 100)) {

                            int b = platMerOrderService.success(order);

                            if (b > 0) {
                                log.info("jinxin launch success");

                                report(order);
                                log.info("1");
                                return "1";
                            } else {
                                log.error("jinxin callback error");
                                return "error";
                            }

                        } else {
                            log.error("jinxin callback amount is error");
                            return "amount is error";
                        }

                    } else {
                        log.error("jinxin callback sign error");
                        return "sign error";
                    }

                } catch (RuntimeException ex) {
                    log.error("jinxin callback notify EpayException", ex);
                    return "error" + ex.getMessage();
                } catch (Exception ex) {
                    log.error("jinxin callback notify Exception", ex);
                    return "system ex ";
                } finally {
                    unlock(orderId);
                }

            } else {
                log.error("jinxin callback plat order id is empty" + orderId);
                return "plat order id is empty";
            }

        } else {
            log.error("jinxin callback plat order is error" + jsonObject.toJSONString());
            return "plat order status is error";
        }
    }

    public String longjuanfengUrl(JSONObject jsonObject) {
        log.info("jsonobject {}", jsonObject);

        String merchOrder = jsonObject.getString("sh_order");


        String sign = jsonObject.getString("sign");
        String status = jsonObject.getString("status");

        if (!status.equals("success")) {
            log.error("plat order is error" + jsonObject.toJSONString());
            return "plat order is error";
        }

        //message
        jsonObject.remove("sign");
        SortedMap sortedMap = new TreeMap();
        for (String key : jsonObject.keySet()) {

            sortedMap.put(key, jsonObject.getString(key));
        }


        if (StringUtils.isEmpty(merchOrder)) {

            log.error("plat order id is empty" + merchOrder);
            return "plat order id is empty";
        }

        try {
            if (!lock(merchOrder)) {
                return "error";
            }


            PlatMerOrder byOrderId = platMerOrderService.getByOrderId(merchOrder);

            if (StringUtils.equals(byOrderId.getStat(), "2")) {
                return "success";
            }

            PlatMer byMerIdCache = platMerService.getByMerIdCache(byOrderId.getMerId());

            if (byMerIdCache == null) {
                return "plat mer is empty not fund";
            }

            String s = convertUrl(sortedMap, "&", "=") + "&key=" + byMerIdCache.getPrivateKey();
//            String sign = SecureUtil.md5(s +"&"+ byMerIdCache.getPrivateKey()).toLowerCase();
            log.error(" sign url error {}", s);
            if (!SecureUtil.md5(s).toLowerCase().equals(sign)) {
                return "sign error";
            }


            if (byOrderId.getAmount().doubleValue() != jsonObject.getDouble("money")) {
                return "amount is  error";
            }

            int b = platMerOrderService.success(byOrderId);
            if (b > 0) {


                report(byOrderId);
                log.info("success");

                return "success";
            }
            return "error";

        } catch (RuntimeException ex) {
            log.error("notify EpayException", ex);
            return "error" + ex.getMessage();
        } catch (Exception ex) {
            log.error("notify Exception", ex);
            return "system ex ";
        } finally {
            unlock(merchOrder);
        }
    }

    public String epayUrl(JSONObject jsonObject) {
        return jinshunfuUrl(jsonObject);
    }


    public String yuanwang2Url(JSONObject jsonObject) {
        return yuanwangUrl(jsonObject);
    }

    public String xiangyunUrl(JSONObject jsonObject) {
        log.info("jsonobject {}", jsonObject);

        String merchOrder = jsonObject.getString("outTradeNo");


        String sign = jsonObject.getString("sign");
        String status = jsonObject.getString("status");

        if (!status.equals("1")) {
            log.error("plat order is error" + jsonObject.toJSONString());
            return "plat order is error";
        }

        //message
        jsonObject.remove("sign");
        jsonObject.remove("signType");
        jsonObject.remove("charset");
        SortedMap sortedMap = new TreeMap();
        for (String key : jsonObject.keySet()) {

            sortedMap.put(key, jsonObject.getString(key));
        }


        if (StringUtils.isEmpty(merchOrder)) {

            log.error("plat order id is empty" + merchOrder);
            return "plat order id is empty";
        }

        try {
            if (!lock(merchOrder)) {
                return "error";
            }


            PlatMerOrder byOrderId = platMerOrderService.getByOrderId(merchOrder);

            if (StringUtils.equals(byOrderId.getStat(), "2")) {
                return "success";
            }

            PlatMer byMerIdCache = platMerService.getByMerIdCache(byOrderId.getMerId());

            if (byMerIdCache == null) {
                return "plat mer is empty not fund";
            }

            String s = convertUrl(sortedMap, "&", "=") + "&" + byMerIdCache.getPrivateKey();
//            String sign = SecureUtil.md5(s +"&"+ byMerIdCache.getPrivateKey()).toLowerCase();
            log.error(" sign url error {}", s);



            if (!SecureUtil.md5(s).equals(sign)) {
                return "sign error";
            }


            if (byOrderId.getAmount().doubleValue() != jsonObject.getDouble("amount")) {
                return "amount is  error";
            }

            int b = platMerOrderService.success(byOrderId);
            if (b > 0) {


                report(byOrderId);
                log.info("SUCCESS");

                return "SUCCESS";
            }
            return "error";

        } catch (RuntimeException ex) {
            log.error("notify EpayException", ex);
            return "error" + ex.getMessage();
        } catch (Exception ex) {
            log.error("notify Exception", ex);
            return "system ex ";
        } finally {
            unlock(merchOrder);
        }
    }

    public String liantongUrl(JSONObject jsonObject) {
        return wuyueUrl(jsonObject);
    }

    public String qiantongUrl(JSONObject jsonObject) {
        log.info("jsonobject {}", jsonObject);

        String merchOrder = jsonObject.getString("outTradeNo");


        String sign = jsonObject.getString("sign");
        String status = jsonObject.getString("tradeStatus");

        if (!status.equals("SUCCESS")) {
            log.error("plat order is error" + jsonObject.toJSONString());
            return "plat order is error";
        }

        //message
        jsonObject.remove("sign");
        SortedMap sortedMap = new TreeMap();
        for (String key : jsonObject.keySet()) {

            sortedMap.put(key, jsonObject.getString(key));
        }


        if (StringUtils.isEmpty(merchOrder)) {

            log.error("plat order id is empty" + merchOrder);
            return "plat order id is empty";
        }

        try {
            if (!lock(merchOrder)) {
                return "error";
            }


            PlatMerOrder byOrderId = platMerOrderService.getByOrderId(merchOrder);

            if (StringUtils.equals(byOrderId.getStat(), "2")) {
                return "success";
            }

            PlatMer byMerIdCache = platMerService.getByMerIdCache(byOrderId.getMerId());

            if (byMerIdCache == null) {
                return "plat mer is empty not fund";
            }

            String s = convertUrl(sortedMap, "&", "=") + "&paySecret=" + byMerIdCache.getPrivateKey();
//            String sign = SecureUtil.md5(s +"&"+ byMerIdCache.getPrivateKey()).toLowerCase();
            log.error(" sign url error {}", s);
            if (!SecureUtil.md5(s).toUpperCase().equals(sign)) {
                return "sign error";
            }


            if (byOrderId.getAmount().doubleValue() != jsonObject.getDouble("orderPrice")) {
                return "amount is  error";
            }

            int b = platMerOrderService.success(byOrderId);
            if (b > 0) {


                report(byOrderId);
                log.info("success");

                return "success";
            }
            return "error";

        } catch (RuntimeException ex) {
            log.error("notify EpayException", ex);
            return "error" + ex.getMessage();
        } catch (Exception ex) {
            log.error("notify Exception", ex);
            return "system ex ";
        } finally {
            unlock(merchOrder);
        }
    }

        public String kuaifutongUrl(JSONObject jsonObject) {
            log.info("jsonobject {}", jsonObject);

            String merchOrder = jsonObject.getString("trade_id");


            String sign = jsonObject.getString("sign");
            String status = jsonObject.getString("result_code");

            if (!status.equals("0")) {
                log.error("plat order is error" + jsonObject.toJSONString());
                return "plat order is error";
            }

            //message
            jsonObject.remove("sign");
            SortedMap sortedMap = new TreeMap();
            for (String key : jsonObject.keySet()) {

                sortedMap.put(key, jsonObject.getString(key));
            }


            if (StringUtils.isEmpty(merchOrder)) {

                log.error("plat order id is empty" + merchOrder);
                return "plat order id is empty";
            }

            try {
                if (!lock(merchOrder)) {
                    return "error";
                }


                PlatMerOrder byOrderId = platMerOrderService.getByOrderId(merchOrder);

                if (StringUtils.equals(byOrderId.getStat(), "2")) {
                    return "success";
                }

                PlatMer byMerIdCache = platMerService.getByMerIdCache(byOrderId.getMerId());

                if (byMerIdCache == null) {
                    return "plat mer is empty not fund";
                }

                String s = byMerIdCache.getPrivateKey() + convertUrl(sortedMap, "&", "=") + byMerIdCache.getPrivateKey();
                log.error(" sign url error {}", s);
                if (!SecureUtil.md5(s).toUpperCase().equals(sign)) {
                    return "sign error";
                }


                if (byOrderId.getAmount().doubleValue() != jsonObject.getDouble("fee")) {
                    return "amount is  error";
                }

                int b = platMerOrderService.success(byOrderId);
                if (b > 0) {


                    report(byOrderId);
                    log.info("ok");

                    return "ok";
                }
                return "error";

            } catch (RuntimeException ex) {
                log.error("notify EpayException", ex);
                return "error" + ex.getMessage();
            } catch (Exception ex) {
                log.error("notify Exception", ex);
                return "system ex ";
            } finally {
                unlock(merchOrder);
            }
        }

    public String haifengUrl(JSONObject jsonObject) {
        return jinxinUrl(jsonObject);
    }

    public String juli2Url(JSONObject jsonObject) {
        log.info("jsonobject {}", jsonObject);

        String merchOrder = jsonObject.getString("mch_order_no");


        String sign = jsonObject.getString("sign");
        String status = jsonObject.getString("status");

        if (!status.equals("1")) {
            log.error("plat order is error" + jsonObject.toJSONString());
            return "plat order is error";
        }

        //message
        jsonObject.remove("sign");
        jsonObject.remove("t");
        SortedMap sortedMap = new TreeMap();
        for (String key : jsonObject.keySet()) {

            sortedMap.put(key, jsonObject.getString(key));
        }


        if (StringUtils.isEmpty(merchOrder)) {

            log.error("plat order id is empty" + merchOrder);
            return "plat order id is empty";
        }

        try {
            if (!lock(merchOrder)) {
                return "error";
            }


            PlatMerOrder byOrderId = platMerOrderService.getByOrderId(merchOrder);

            if (StringUtils.equals(byOrderId.getStat(), "2")) {
                return "success";
            }

            PlatMer byMerIdCache = platMerService.getByMerIdCache(byOrderId.getMerId());

            if (byMerIdCache == null) {
                return "plat mer is empty not fund";
            }

            String s = convertUrlIsEmpty(sortedMap, "&", "=") + "&key=" +byMerIdCache.getPrivateKey();
            log.info(" sign url error {}", s);

            String si = SecureUtil.md5(s);
            log.info("sign {}", si);

            if (!si.equals(sign)) {
                return "sign error";
            }


            if (byOrderId.getAmount().doubleValue() != jsonObject.getDouble("total_fee")) {
                log.error("amount error {}    {}", byOrderId.getAmount().doubleValue(),jsonObject.getDouble("total_fee") );
                return "amount is  error";
            }

            int b = platMerOrderService.success(byOrderId);
            if (b > 0) {


                report(byOrderId);
                log.info("Success");

                return "Success";
            }
            return "error";

        } catch (RuntimeException ex) {
            log.error("notify EpayException", ex);
            return "error" + ex.getMessage();
        } catch (Exception ex) {
            log.error("notify Exception", ex);
            return "system ex ";
        } finally {
            unlock(merchOrder);
        }
    }


    public String bUrl(JSONObject jsonObject) {
        log.info("jsonobject {}", jsonObject);

        String merchOrder = jsonObject.getString("orderid");


        String sign = jsonObject.getString("sign");
        String status = jsonObject.getString("status");

        if (!status.equals("0000")) {
            log.error("plat order is error" + jsonObject.toJSONString());
            return "plat order is error";
        }

        //message
        jsonObject.remove("sign");
        SortedMap sortedMap = new TreeMap();
        for (String key : jsonObject.keySet()) {

            sortedMap.put(key, jsonObject.getString(key));
        }


        if (StringUtils.isEmpty(merchOrder)) {

            log.error("plat order id is empty" + merchOrder);
            return "plat order id is empty";
        }

        try {
            if (!lock(merchOrder)) {
                return "error";
            }


            PlatMerOrder byOrderId = platMerOrderService.getByOrderId(merchOrder);

            if (StringUtils.equals(byOrderId.getStat(), "2")) {
                return "success";
            }

            PlatMer byMerIdCache = platMerService.getByMerIdCache(byOrderId.getMerId());

            if (byMerIdCache == null) {
                return "plat mer is empty not fund";
            }

            String s = "money="+jsonObject.getString("money") + "&orderid=" + jsonObject.getString("orderid") +
                    "&status=" + jsonObject.getString("status") + "&key=" + byMerIdCache.getPrivateKey();

            log.info(" sign url error {}", s);

            String si = SecureUtil.md5(s);
            log.info("sign {}", sign);

            if (!si.equals(sign)) {
                return "sign error";
            }


            if (byOrderId.getAmount().doubleValue() != jsonObject.getDouble("total_fee")) {
                log.error("amount error {}    {}", byOrderId.getAmount().doubleValue(),jsonObject.getDouble("total_fee") );
                return "amount is  error";
            }

            int b = platMerOrderService.success(byOrderId);
            if (b > 0) {


                report(byOrderId);
                log.info("success");

                return "success";
            }
            return "error";

        } catch (RuntimeException ex) {
            log.error("notify EpayException", ex);
            return "error" + ex.getMessage();
        } catch (Exception ex) {
            log.error("notify Exception", ex);
            return "system ex ";
        } finally {
            unlock(merchOrder);
        }
    }

    public String kk2Url(JSONObject jsonObject) {
        log.info("jsonobject {}", jsonObject);

        String merchOrder = jsonObject.getString("order_id");


        String sign = jsonObject.getString("sign");
        String status = jsonObject.getString("status");

        if (!status.equals("succ")) {
            log.error("plat order is error" + jsonObject.toJSONString());
            return "plat order is error";
        }

        if (StringUtils.isEmpty(merchOrder)) {

            log.error("plat order id is empty" + merchOrder);
            return "plat order id is empty";
        }

        try {
            if (!lock(merchOrder)) {
                return "error";
            }


            PlatMerOrder byOrderId = platMerOrderService.getByOrderId(merchOrder);

            if (StringUtils.equals(byOrderId.getStat(), "2")) {
                return "success";
            }

            PlatMer byMerIdCache = platMerService.getByMerIdCache(byOrderId.getMerId());

            if (byMerIdCache == null) {
                return "plat mer is empty not fund";
            }

            //message
            jsonObject.remove("sign");
            SortedMap sortedMap = new TreeMap();
            for (String key : jsonObject.keySet()) {

                sortedMap.put(key, jsonObject.getString(key));
            }

            String s = convertUrlIsEmpty(sortedMap, "&", "=") + "&key=" +byMerIdCache.getPrivateKey();
            log.info(" sign url error {}", s);

            String si = SecureUtil.md5(s);
            log.info("sign {}", sign);

            if (!si.equals(sign)) {
                return "sign error";
            }


            if (byOrderId.getAmount().doubleValue() != jsonObject.getDouble("amount")) {
                log.error("amount error {}    {}", byOrderId.getAmount().doubleValue(),jsonObject.getDouble("amount") );
                return "amount is  error";
            }

            int b = platMerOrderService.success(byOrderId);
            if (b > 0) {


                report(byOrderId);
                log.info("success");

                return "success";
            }
            return "error";

        } catch (RuntimeException ex) {
            log.error("notify EpayException", ex);
            return "error" + ex.getMessage();
        } catch (Exception ex) {
            log.error("notify Exception", ex);
            return "system ex ";
        } finally {
            unlock(merchOrder);
        }
    }

    public String liantongkamiUrl(JSONObject jsonObject) {
        return wuyueUrl(jsonObject);
    }

    public String tianyuPay(JSONObject jsonObject) {
        return jinzhiPay(jsonObject);
    }
    public String b2cShangtian(JSONObject jsonObject) {

        String merchOrder = jsonObject.getString("orderId");
//        String returncode = jsonObject.getString("payResult");

//        if (!returncode.equals("8")) {
//            log.error("plat order is error" + jsonObject.toJSONString());
//            return "plat order is error";
//        }
        if (StringUtils.isEmpty(merchOrder)) {
            log.error("plat order id is empty" + merchOrder);
            return "plat order id is empty";
        }
        try {
            if (!lock(merchOrder)) {
                return "error";
            }
            PlatMerOrder byOrderId = platMerOrderService.getByOrderId(merchOrder);
            if (StringUtils.equals(byOrderId.getStat(), "2")) {
                return "success";
            }

            if (byOrderId.getAmount().doubleValue() != jsonObject.getBigDecimal("amount").doubleValue()) {
                return "amount is  error";
            }
            int b = platMerOrderService.success(byOrderId);
            if (b > 0) {
                report(byOrderId);
                log.info("success");
                return "success";
            }
            return "error";

        } catch (RuntimeException ex) {
            log.error("notify EpayException", ex);
            return "error" + ex.getMessage();
        } catch (Exception ex) {
            log.error("notify Excpfpayeption", ex);
            return "system ex ";
        } finally {
            unlock(merchOrder);
        }

    }

    public String longjuanfeng2Url(JSONObject jsonObject) {
        log.info("jsonobject {}", jsonObject);

        String merchOrder = jsonObject.getString("orderNumber");


        String sign = jsonObject.getString("token");
//        String status = jsonObject.getString("status");

//        if (!status.equals("succ")) {
//            log.error("plzfbat order is error" + jsonObject.toJSONString());
//            return "plat order is error";
//        }

        if (StringUtils.isEmpty(merchOrder)) {

            log.error("plat order id is empty" + merchOrder);
            return "plat order id is empty";
        }

        try {
            if (!lock(merchOrder)) {
                return "error";
            }


            PlatMerOrder byOrderId = platMerOrderService.getByOrderId(merchOrder);

            if (StringUtils.equals(byOrderId.getStat(), "2")) {
                return "success";
            }

            PlatMer byMerIdCache = platMerService.getByMerIdCache(byOrderId.getMerId());

            if (byMerIdCache == null) {
                return "plat mer is empty not fund";
            }

            //message
            Map<String, Object> sortedMap = new LinkedHashMap<>();
            sortedMap.put("code", byMerIdCache.getPrivateKey());
            sortedMap.put("orderNumber", jsonObject.getString("orderNumber"));
            sortedMap.put("money", jsonObject.getString("money"));
            sortedMap.put("notifyurl", jsonObject.getString("notifyurl"));
            sortedMap.put("key", jsonObject.getString("key"));

            String s = JSON.toJSONString(sortedMap);
            log.info(" sign url error {}", s);

            String si = SecureUtil.md5(s);
            log.info("sign {}", si);

            if (!si.equals(sign)) {
                return "sign error";
            }


            if (byOrderId.getAmount().doubleValue() != jsonObject.getDouble("money")) {
                log.error("amount error {}    {}", byOrderId.getAmount().doubleValue(),jsonObject.getDouble("amount") );
                return "amount is  error";
            }

            int b = platMerOrderService.success(byOrderId);
            if (b > 0) {


                report(byOrderId);
                log.info("success");

                return "success";
            }
            return "error";

        } catch (RuntimeException ex) {
            log.error("notify EpayException", ex);
            return "error" + ex.getMessage();
        } catch (Exception ex) {
            log.error("notify Exception", ex);
            return "system ex ";
        } finally {
            unlock(merchOrder);
        }

    }

    public String svipUrl(JSONObject jsonObject) {
        return jiuxuan(jsonObject);
    }

    public String pikaqiuUrl(JSONObject jsonObject) {
        return juzi(jsonObject);
    }

    public String kaerhongbaoUrl(JSONObject jsonObject) {
        return jiuxuan(jsonObject);
    }

    public String tudou2Url(JSONObject jsonObject) {
        return zfb(jsonObject);
    }

    public String yifuUrl(JSONObject jsonObject) {
        log.info("jsonobject {}", jsonObject);

        String merchOrder = jsonObject.getString("order_id");


        String sign = jsonObject.getString("sign");
        String status = jsonObject.getString("status");

        if (!status.equals("1")) {
            log.error("plzfbat order is error" + jsonObject.toJSONString());
            return "plat order is error";
        }

        if (StringUtils.isEmpty(merchOrder)) {

            log.error("plat order id is empty" + merchOrder);
            return "plat order id is empty";
        }

        try {
            if (!lock(merchOrder)) {
                return "error";
            }


            PlatMerOrder byOrderId = platMerOrderService.getByOrderId(merchOrder);

            if (StringUtils.equals(byOrderId.getStat(), "2")) {
                return "success";
            }

            PlatMer byMerIdCache = platMerService.getByMerIdCache(byOrderId.getMerId());

            if (byMerIdCache == null) {
                return "plat mer is empty not fund";
            }

            jsonObject.remove("sign");
            SortedMap sortedMap = new TreeMap();
            for (String key : jsonObject.keySet()) {

                sortedMap.put(key, jsonObject.getString(key));
            }


            String s = convertUrlNotEmpty(sortedMap, "&", "=") + "&key=" + byMerIdCache.getPrivateKey();
            log.info(" sign url error {}", s);

            String si = SecureUtil.md5(s);
            log.info("sign {}", si);

            if (!si.equals(sign)) {
                return "sign error";
            }


            if (byOrderId.getAmount().doubleValue() != jsonObject.getBigDecimal("real_amount").divide(BigDecimal.TEN.multiply(BigDecimal.TEN)).doubleValue()) {
                log.error("amount error {}    {}", byOrderId.getAmount().doubleValue(),jsonObject.getDouble("real_amount") );
                return "amount is  error";
            }

            int b = platMerOrderService.success(byOrderId);
            if (b > 0) {


                report(byOrderId);
                log.info("success");

                return "success";
            }
            return "error";

        } catch (RuntimeException ex) {
            log.error("notify EpayException", ex);
            return "error" + ex.getMessage();
        } catch (Exception ex) {
            log.error("notify Exception", ex);
            return "system ex ";
        } finally {
            unlock(merchOrder);
        }

    }

    public String jubaopenUrl(JSONObject jsonObject) {
        log.info("jsonobject {}", jsonObject);

        String merchOrder = jsonObject.getString("payId");


        String sign = jsonObject.getString("sign");
//        String status = jsonObject.getString("status");
//
//        if (!status.equals("1")) {
//            log.error("plzfbat order is error" + jsonObject.toJSONString());
//            return "plat order is error";
//        }

        if (StringUtils.isEmpty(merchOrder)) {

            log.error("plat order id is empty" + merchOrder);
            return "plat order id is empty";
        }

        try {
            if (!lock(merchOrder)) {
                return "error";
            }


            PlatMerOrder byOrderId = platMerOrderService.getByOrderId(merchOrder);

            if (StringUtils.equals(byOrderId.getStat(), "2")) {
                return "success";
            }

            PlatMer byMerIdCache = platMerService.getByMerIdCache(byOrderId.getMerId());

            if (byMerIdCache == null) {
                return "plat mer is empty not fund";
            }

            jsonObject.remove("sign");
            SortedMap sortedMap = new TreeMap();
            for (String key : jsonObject.keySet()) {

                sortedMap.put(key, jsonObject.getString(key));
            }


            String si = SecureUtil.md5(jsonObject.getString("payId") +
                    jsonObject.getString("param") +  jsonObject.getString("param") +
                    jsonObject.getString("price") + jsonObject.getString("reallyPrice") + byMerIdCache.getPrivateKey());
            log.info("sign {}", si);

            if (!si.equals(sign)) {
                return "sign error";
            }


            if (byOrderId.getAmount().doubleValue() != jsonObject.getBigDecimal("reallyPrice").doubleValue()) {
                log.error("amount error {}    {}", byOrderId.getAmount().doubleValue(),jsonObject.getDouble("reallyPrice") );
                return "amount is  error";
            }

            int b = platMerOrderService.success(byOrderId);
            if (b > 0) {


                report(byOrderId);
                log.info("success");

                return "success";
            }
            return "error";

        } catch (RuntimeException ex) {
            log.error("notify EpayException", ex);
            return "error" + ex.getMessage();
        } catch (Exception ex) {
            log.error("notify Exception", ex);
            return "system ex ";
        } finally {
            unlock(merchOrder);
        }

    }

    public String youziUrl(JSONObject jsonObject) {
        return qianjinfuUrl(jsonObject);
    }

    public String huitong2Url(JSONObject jsonObject) {
        return yinFuTong(jsonObject);
    }

    public String suixingUrl(JSONObject jsonObject) {
        log.info("jsonobject {}", jsonObject);

        String merchOrder = jsonObject.getString("TxSN");
        String sign = jsonObject.getString("Signature");
        String status = jsonObject.getString("Status");

        if (!status.equals("1")) {
            log.error("plzfbat order is error" + jsonObject.toJSONString());
            return "plat order is error";
        }

        if (StringUtils.isEmpty(merchOrder)) {

            log.error("plat order id is empty" + merchOrder);
            return "plat order id is empty";
        }

        try {
            if (!lock(merchOrder)) {
                return "error";
            }


            PlatMerOrder byOrderId = platMerOrderService.getByOrderId(merchOrder);

            if (StringUtils.equals(byOrderId.getStat(), "2")) { return "success";
            }

            PlatMer byMerIdCache = platMerService.getByMerIdCache(byOrderId.getMerId());

            if (byMerIdCache == null) {
                return "plat mer is empty not fund";
            }

            jsonObject.remove("SignMethod");
            jsonObject.remove("Signature");

            SortedMap sortedMap = new TreeMap();
            for (String key : jsonObject.keySet()) {
                sortedMap.put(key, jsonObject.getString(key));
            }

            String s = convertUrlNotEmpty(sortedMap, "&", "=") + byMerIdCache.getPrivateKey();
            log.info("notify s {}", s);

            String md5Sign = SecureUtil.md5(s);
            log.info("notify md5Sign {}", md5Sign);

            if (!md5Sign.equals(sign)) {
                log.error("sign error");
                return "sign error";
            }


            if (byOrderId.getAmount().doubleValue() != jsonObject.getBigDecimal("PaidAmount").divide(new BigDecimal(100)).doubleValue()) {
                log.error("amount error {}    {}", byOrderId.getAmount().doubleValue(),jsonObject.getDouble("PaidAmount") );
                return "amount is  error";
            }

            int b = platMerOrderService.success(byOrderId);
            if (b > 0) {


                report(byOrderId);
                log.info("success");

                return "success";
            }
            return "error";

        } catch (RuntimeException ex) {
            log.error("notify EpayException", ex);
            return "error" + ex.getMessage();
        } catch (Exception ex) {
            log.error("notify Exception", ex);
            return "system ex ";
        } finally {
            unlock(merchOrder);
        }

    }

    public String xyUrl(JSONObject jsonObject) {
        String merchOrder = jsonObject.getString("orderId");
        // String returncode = jsonObject.getString("payResult");

        // if (!returncode.equals("8")) {
        // log.error("plat order is error" + jsonObject.toJSONString());
        // return "plat order is error";
        // }
        if (StringUtils.isEmpty(merchOrder)) {
            log.error("plat order id is empty" + merchOrder);
            return "plat order id is empty";
        }
        try {
            if (!lock(merchOrder)) {
                return "error";
            }
            PlatMerOrder byOrderId = platMerOrderService.getByOrderId(merchOrder);
            if (StringUtils.equals(byOrderId.getStat(), "2")) {
                return "success";
            }

            if (byOrderId.getAmount().doubleValue() != jsonObject.getBigDecimal("amount").doubleValue()) {
                return "amount is  error";
            }
            int b = platMerOrderService.success(byOrderId);
            if (b > 0) {
                report(byOrderId);
                log.info("success");
                return "success";
            }
            return "error";

        } catch (RuntimeException ex) {
            log.error("notify EpayException", ex);
            return "error" + ex.getMessage();
        } catch (Exception ex) {
            log.error("notify Excpfpayeption", ex);
            return "system ex ";
        } finally {
            unlock(merchOrder);
        }

    }

    public String ncgepay2Url(JSONObject jsonObject) {
        return ncgepay(jsonObject);
    }

    public String feifanUrl(JSONObject jsonObject) {
        return kuaizhifuUrl(jsonObject);
    }

    public String chaojifuUrl(JSONObject jsonObject) {
        return binli(jsonObject);
    }

    public String hx2Url(JSONObject jsonObject) {
        return jinxinUrl(jsonObject);
    }

    public String chuangxinUrl(JSONObject jsonObject) {
        log.info("kuaizhifu jsonObject " + jsonObject);
        String orderId = jsonObject.getJSONObject("data").getString("order_no");
        String status =  jsonObject.getJSONObject("data").getString("status");
        String sign = jsonObject.getString("sign");
        log.info(String.format("dy orderId=%s, status=%s, sign=%s", orderId, status, sign));

        if ("1000".equals(status)) {

            if (!StringUtils.isEmpty(orderId)) {

                try {

                    if (!lock(orderId)) {
                        log.error("pilin is lock");
                        return "error";
                    }

                    PlatMerOrder order = platMerOrderService.getByOrderId(orderId);
                    if (StringUtils.equals(order.getStat(), "2")) {
                        return "success";
                    }

                    PlatMer byMerIdCache = platMerService.getByMerIdCache(order.getMerId());
                    if (byMerIdCache == null) {
                        return "plat mer is empty not fund";
                    }

                    jsonObject.remove("sign");
                    jsonObject.remove("sign_type");
                    Map<String, String> map = new TreeMap<>();
                    for (String key : jsonObject.keySet()) {


                        if (key.equals("data")) {
                            for (String datakey : jsonObject.getJSONObject("data").keySet()) {

                                map.put(datakey, jsonObject.getJSONObject("data").get(datakey).toString());
                            }
                        } else {
                            map.put(key, jsonObject.get(key).toString());
                        }
                    }
                    String s = convertUrl(map, "&", "=") + "&key=" + byMerIdCache.getPrivateKey();
                    String md5Str = SecureUtil.md5(s).toUpperCase();
                    log.info("s " + s);
                    log.info("md5(s) " + md5Str);

                    if (md5Str.equals(sign)) {

                        if (order.getAmount().doubleValue() == jsonObject.getJSONObject("data").getDouble("amount")) {

                            int b = platMerOrderService.success(order);

                            if (b > 0) {
                                report(order);
                                log.info("kuaizhifu success");
                                return "success";
                            } else {
                                log.error("error");
                                return "error";
                            }

                        } else {
                            log.error("amount is error");
                            return "amount is error";
                        }

                    } else {
                        log.error("sign error");
                        return "sign error";
                    }

                } catch (RuntimeException ex) {
                    log.error("notify EpayException", ex);
                    return "error" + ex.getMessage();
                } catch (Exception ex) {
                    log.error("notify Exception", ex);
                    return "system ex ";
                } finally {
                    unlock(orderId);
                }

            } else {
                log.error("plat order id is empty" + orderId);
                return "plat order id is empty";
            }

        } else {
            log.error("plat order is error" + jsonObject.toJSONString());
            return "plat order status is error";
        }

    }

    public String huibaoUrl(JSONObject jsonObject) {

        return stormUrl(jsonObject);
    }

    public String yifanUrl(JSONObject jsonObject) {
        log.info("kuaizhifu jsonObject " + jsonObject);
        String orderId = jsonObject.getString("appOrder");
        String status = jsonObject.getString("cash_is");
        String sign = jsonObject.getString("sign");
        log.info(String.format("dy orderId=%s, status=%s, sign=%s", orderId, status, sign));

        if ("1".equals(status)) {

            if (!StringUtils.isEmpty(orderId)) {

                try {

                    if (!lock(orderId)) {
                        log.error("pilin is lock");
                        return "error";
                    }

                    PlatMerOrder order = platMerOrderService.getByOrderId(orderId);
                    if (StringUtils.equals(order.getStat(), "2")) {
                        return "success";
                    }

                    PlatMer byMerIdCache = platMerService.getByMerIdCache(order.getMerId());
                    if (byMerIdCache == null) {
                        return "plat mer is empty not fund";
                    }

                    jsonObject.remove("sign");
                    Map<String, String> map = new TreeMap<>();
                    for (String key : jsonObject.keySet()) {
                        map.put(key, jsonObject.get(key).toString());
                    }

                    StringBuffer a = new StringBuffer();
                    for (Map.Entry<String, String> entry : map.entrySet()) {
                        a.append(entry.getValue());
                    }

                    String s =a.toString()+byMerIdCache.getPrivateKey();
                    String md5Str = SecureUtil.md5(s).toUpperCase();
                    log.info("s " + s);
                    log.info("md5(s) " + md5Str);

                    if (md5Str.equals(sign)) {

                        if (order.getAmount().doubleValue() == jsonObject.getBigDecimal("amt").divide(new BigDecimal(100)).doubleValue()) {

                            int b = platMerOrderService.success(order);

                            if (b > 0) {
                                report(order);
                                log.info("kuaizhifu success");
                                return "success";
                            } else {
                                log.error("error");
                                return "error";
                            }

                        } else {
                            log.error("amount is error");
                            return "amount is error";
                        }

                    } else {
                        log.error("sign error");
                        return "sign error";
                    }

                } catch (RuntimeException ex) {
                    log.error("notify EpayException", ex);
                    return "error" + ex.getMessage();
                } catch (Exception ex) {
                    log.error("notify Exception", ex);
                    return "system ex ";
                } finally {
                    unlock(orderId);
                }

            } else {
                log.error("plat order id is empty" + orderId);
                return "plat order id is empty";
            }

        } else {
            log.error("plat order is error" + jsonObject.toJSONString());
            return "plat order status is error";
        }

    }

    public String longzhifuUrl(JSONObject jsonObject) {
        return binli(jsonObject);
    }

    public String hxUrl(JSONObject jsonObject) {
        return binli(jsonObject);
    }

    public String mudanUrl(JSONObject jsonObject) {
        return dongyayihao(jsonObject);
    }

    public String ncnewverUrl(JSONObject jsonObject) {
        log.info("json {}", jsonObject);
//        String returncode = jsonObject.getString("result");
        String orderid = jsonObject.getString("out_trade_no");
        double amount = jsonObject.getDouble("order_money");
        log.error(" order id " + orderid);
        String sign = jsonObject.getString("sign");
        jsonObject.remove("sign");
        log.error(" order id " + orderid);


//        if (!returncode.equals("Y")) {
//            log.error("plat order is error  status error" + jsonObject.toJSONString());
//            return "plat order is error is status error";
//        }
        if (StringUtils.isEmpty(orderid)) {

            log.error("plat order id is empty notify order" + orderid);
            return "plat order  order id is empty";
        }


        try {
            if (!lock(orderid)) {
                return "error";
            }


            PlatMerOrder byOrderId = platMerOrderService.getByOrderId(orderid);

            if (StringUtils.equals(byOrderId.getStat(), "2")) {
                return "Success";
            }


            double min = byOrderId.getAmount().doubleValue() - 1;
            double max = byOrderId.getAmount().doubleValue() + 1;


            /**
             * 浮动金额
             */
            if (!(amount >= min && amount <= max)) {

//            if (byOrderId.getAmount().doubleValue() != amount) {
                return "amount is  error";
            }

            PlatMer byMerIdCache = platMerService.getByMerIdCache(byOrderId.getMerId());

            if (byMerIdCache == null) {
                return "plat mer is empty not fund";
            }


            jsonObject.remove("sign");
            Map<String, String> map = new TreeMap<>();
            for (String key : jsonObject.keySet()) {
                map.put(key, jsonObject.get(key).toString());
            }

            String s = convertUrl(map, "&", "=")+ "&secret=" + byMerIdCache.getPrivateKey();
            log.error("result sign {}", s);

            if (!SecureUtil.md5(s).toUpperCase().equals(sign)) {

                log.error(" sigin error {}", jsonObject.toJSONString());
                return "sign error";
            }

            byOrderId.setRealAmount(new BigDecimal(amount));
            int b = platMerOrderService.success(byOrderId);
            if (b > 0) {


                report(byOrderId);

                return "Success";
            }
            return "error";

        } catch (RuntimeException ex) {
            log.error("notify EpayException", ex);
            return "error" + ex.getMessage();
        } catch (Exception ex) {
            log.error("notify Exception", ex);
            return "system ex ";
        } finally {
            unlock(orderid);
        }    }

    public String youyifu2Url(JSONObject jsonObject) {
        String merchOrder = jsonObject.getString("orderid");
        String returncode = jsonObject.getString("status");
        String sign = jsonObject.getString("sign");
        jsonObject.remove("sign");
        jsonObject.remove("attach");
        log.error(" order id " + merchOrder);
        SortedMap sortedMap = new TreeMap();
        for (String key : jsonObject.keySet()) {
            sortedMap.put(key, jsonObject.getString(key));
        }

        if (!returncode.equals("2")) {
            log.error("plat order is error" + jsonObject.toJSONString());
            return "plat order is error";
        }
        if (StringUtils.isEmpty(merchOrder)) {
            log.error("plat order id is empty" + merchOrder);
            return "plat order id is empty";
        }
        try {
            if (!lock(merchOrder)) {
                return "error";
            }
            PlatMerOrder byOrderId = platMerOrderService.getByOrderId(merchOrder);
            if (StringUtils.equals(byOrderId.getStat(), "2")) {
                return "OK";
            }
            PlatMer byMerIdCache = platMerService.getByMerIdCache(byOrderId.getMerId());
            if (byMerIdCache == null) {
                return "plat mer is empty not fund";
            }
            String s = convertUrlIsEmpty(sortedMap, "&", "=");
            log.info("sign url {}", s);

            log.info("sign url add key {}", s + "&key=" + byMerIdCache.getPrivateKey());
            if (!SecureUtil.md5(s + "&key=" + byMerIdCache.getPrivateKey()).toUpperCase().equals(sign)) {
                return "sign error";
            }

            if (byOrderId.getAmount().doubleValue() != (jsonObject.getDouble("amount"))) {
                return "amount is  error";
            }
            int b = platMerOrderService.success(byOrderId);
            if (b > 0) {
                report(byOrderId);
                return "OK";
            }
            return "error";

        } catch (RuntimeException ex) {
            log.error("notify EpayException", ex);
            return "error" + ex.getMessage();
        } catch (Exception ex) {
            log.error("notify Exception", ex);
            return "system ex ";
        } finally {
            unlock(merchOrder);
        }
    }


    public String yunUrl(JSONObject jsonObject) {
        log.info("json {}", jsonObject);
        String returncode = jsonObject.getString("status");
        String orderid = jsonObject.getString("orderNo");
        double amount = jsonObject.getDouble("order_money");
        String sign = jsonObject.getString("token");


        if (!returncode.equals("success")) {
            log.error("plat order is error  status error" + jsonObject.toJSONString());
            return "plat order is error is status error";
        }
        if (StringUtils.isEmpty(orderid)) {

            log.error("plat order id is empty notify order" + orderid);
            return "plat order  order id is empty";
        }


        try {
            if (!lock(orderid)) {
                return "error";
            }


            PlatMerOrder byOrderId = platMerOrderService.getByOrderId(orderid);

            if (StringUtils.equals(byOrderId.getStat(), "2")) {
                return "Success";
            }

            PlatMer byMerIdCache = platMerService.getByMerIdCache(byOrderId.getMerId());

            if (byMerIdCache == null) {
                return "plat mer is empty not fund";
            }

            String s = byMerIdCache.getPrivateKey() + new SimpleDateFormat("yyyyMMddHH").format(new Date());
            log.info("result sign {}", s);
            if (byOrderId.getAmount().doubleValue() == jsonObject.getDouble("money")) {
                log.info("amount error");
                return "amount error";
            }

            if (!SecureUtil.md5(s).equals(sign)) {
                log.info(" sigin error {}", jsonObject.toJSONString());
                return "sign error";
            }

            byOrderId.setRealAmount(new BigDecimal(amount));
            int b = platMerOrderService.success(byOrderId);
            if (b > 0) {


                report(byOrderId);

                return "callbacksuccess";
            }
            return "error";

        } catch (RuntimeException ex) {
            log.error("notify EpayException", ex);
            return "error" + ex.getMessage();
        } catch (Exception ex) {
            log.error("notify Exception", ex);
            return "system ex ";
        } finally {
            unlock(orderid);
        }
    }
    public String beidouxingUrl(JSONObject jsonObject) {
        log.info("huoxing {}", jsonObject);

        String merchOrder = jsonObject.getString("out_trade_no");


        String sign = jsonObject.getString("sign");

//        String status = jsonObject.getString("code");

//        if (!status.equals("1")) {
//            log.error("plat order is error" + jsonObject.toJSONString());
//            return "plat order status is error";
//        }

        //message
        jsonObject.remove("sign");
        SortedMap sortedMap = new TreeMap();
        for (String key : jsonObject.keySet()) {
            sortedMap.put(key, jsonObject.getString(key));
        }


        if (StringUtils.isEmpty(merchOrder)) {

            log.error("plat order id is empty" + merchOrder);
            return "plat order id is empty";
        }

        try {
            if (!lock(merchOrder)) {
                return "error";
            }


            PlatMerOrder byOrderId = platMerOrderService.getByOrderId(merchOrder);

            if (StringUtils.equals(byOrderId.getStat(), "2")) {
                return "success";
            }

            PlatMer byMerIdCache = platMerService.getByMerIdCache(byOrderId.getMerId());

            if (byMerIdCache == null) {
                return "plat mer is empty not fund";
            }

            String s = convertUrl(sortedMap, "&", "=") +"&KEY="+ byMerIdCache.getPrivateKey();
            log.info(" sign url sign {}", s);

            String mdsign = SecureUtil.md5(s).toUpperCase();
            log.info("sign " + mdsign);

            if (!mdsign.equals(sign)) {
                return "sign error";
            }


            if (byOrderId.getAmount().doubleValue() != jsonObject.getDouble("amount")) {
                return "amount is  error";
            }

            int b = platMerOrderService.success(byOrderId);
            if (b > 0) {


                report(byOrderId);
                log.info("success");
                return "success";
            }
            return "error";

        } catch (RuntimeException ex) {
            log.error("notify EpayException", ex);
            return "error" + ex.getMessage();
        } catch (Exception ex) {
            log.error("notify Exception", ex);
            return "system ex ";
        } finally {
            unlock(merchOrder);
        }
    }
    public String fengyun(JSONObject jsonObject) {
        log.info("huoxing {}", jsonObject);

        String merchOrder = jsonObject.getString("mch_order_id");


        String sign = jsonObject.getString("sign");

        String status = jsonObject.getString("order_status");

        if (!(status.equals("5")||status.equals("2"))) {
            log.error("plat order is error" + jsonObject.toJSONString());
            return "plat order status is error";
        }

        //message
        jsonObject.remove("sign");
        SortedMap sortedMap = new TreeMap();
        for (String key : jsonObject.keySet()) {
            sortedMap.put(key, jsonObject.getString(key));
        }


        if (StringUtils.isEmpty(merchOrder)) {

            log.error("plat order id is empty" + merchOrder);
            return "plat order id is empty";
        }

        try {
            if (!lock(merchOrder)) {
                return "error";
            }


            PlatMerOrder byOrderId = platMerOrderService.getByOrderId(merchOrder);

            if (StringUtils.equals(byOrderId.getStat(), "2")||StringUtils.equals(byOrderId.getStat(), "5")) {
                return "success";
            }

            PlatMer byMerIdCache = platMerService.getByMerIdCache(byOrderId.getMerId());

            if (byMerIdCache == null) {
                return "plat mer is empty not fund";
            }
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMdd");
            String s = convertUrl(sortedMap, "&", "=") +"&"+ byMerIdCache.getPrivateKey()+"&"+simpleDateFormat.format(new Date());
            log.info(" sign url sign {}", s);

            String mdsign = SecureUtil.md5(s).toLowerCase();
            log.info("sign " + mdsign);

            if (!mdsign.equals(sign)) {
                return "sign error";
            }


            if (byOrderId.getAmount().doubleValue() != jsonObject.getDouble("order_amount")) {
                return "amount is  error";
            }

            int b = platMerOrderService.success(byOrderId);
            if (b > 0) {


                report(byOrderId);
                log.info("success");
                return "success";
            }
            return "error";

        } catch (RuntimeException ex) {
            log.error("notify EpayException", ex);
            return "error" + ex.getMessage();
        } catch (Exception ex) {
            log.error("notify Exception", ex);
            return "system ex ";
        } finally {
            unlock(merchOrder);
        }
    }

    public String fuyouPayUrl(JSONObject jsonObject) {
        log.info("huoxing {}", jsonObject);

        String merchOrder = jsonObject.getString("out_trade_no");


        String sign = jsonObject.getString("sign");

        String status = jsonObject.getString("callbacks");

        if (!status.equals("CODE_SUCCESS")) {
            log.error("plat order is error" + jsonObject.toJSONString());
            return "plat order status is error";
        }


        if (StringUtils.isEmpty(merchOrder)) {

            log.error("plat order id is empty" + merchOrder);
            return "plat order id is empty";
        }

        try {
            if (!lock(merchOrder)) {
                return "error";
            }


            PlatMerOrder byOrderId = platMerOrderService.getByOrderId(merchOrder);

            if (StringUtils.equals(byOrderId.getStat(), "2")) {
                return "success";
            }

            PlatMer byMerIdCache = platMerService.getByMerIdCache(byOrderId.getMerId());

            if (byMerIdCache == null) {
                return "plat mer is empty not fund";
            }

            //message
            jsonObject.remove("sign");
            SortedMap sortedMap = new TreeMap();
            for (String key : jsonObject.keySet()) {
                sortedMap.put(key, jsonObject.getString(key));
            }
            JSONObject jsonObject1 = new JSONObject(sortedMap);
            //排序 并 拼装成json字符串
            //paramsString 为排序好的字符串
            String str = convertUrlNotEmpty(sortedMap, "&", "=") + "&key=" + byMerIdCache.getPrivateKey();
            String mdsign = SecureUtil.md5(str).toUpperCase();
            log.warn(" str {}" ,str);

            log.info("sign " + mdsign);

            if (!mdsign.equals(sign)) {
                return "sign error";
            }

            if (byOrderId.getAmount().doubleValue() != jsonObject.getDouble("amount_true").doubleValue()) {
                log.info("amount is error byOrderAmount {}", byOrderId.getAmount());
                return "amount is error";
            }

            int b = platMerOrderService.success(byOrderId);
            if (b > 0) {
                report(byOrderId);
                log.info("OK");
                return "success";
            }
            return "error";

        } catch (RuntimeException ex) {
            log.error("notify EpayException", ex);
            return "error" + ex.getMessage();
        } catch (Exception ex) {
            log.error("notify Exception", ex);
            return "system ex ";
        } finally {
            unlock(merchOrder);
        }
    }
    public String zhaocaiUrl(JSONObject jsonObject) {
        String merchOrder = jsonObject.getString("out_order_no");

        String sign = jsonObject.getString("sign");
        jsonObject.remove("sign");
        jsonObject.remove("attach");


        String status = jsonObject.getString("status");

        if (!status.equals("200")) {
            log.error("plat order is error" + jsonObject.toJSONString());
            return "plat order status is error";
        }
        SortedMap sortedMap = new TreeMap();
        for (String key : jsonObject.keySet()) {
            sortedMap.put(key, jsonObject.getString(key));
        }
        if (StringUtils.isEmpty(merchOrder)) {
            log.error("plat order id is empty" + merchOrder);
            return "plat order id is empty";
        }

        

        
        try {
            if (!lock(merchOrder)) {
                return "error";
            }
            PlatMerOrder byOrderId = platMerOrderService.getByOrderId(merchOrder);
            if (StringUtils.equals(byOrderId.getStat(), "2")) {
                return "ok";
            }
            PlatMer byMerIdCache = platMerService.getByMerIdCache(byOrderId.getMerId());
            String str = convertUrlNotEmpty(sortedMap, "&", "=") + "&key=" + byMerIdCache.getPrivateKey();
            String mdsign = SecureUtil.md5(str).toUpperCase();
            log.info("sign {} url  {}" , mdsign,str);

            if (!mdsign.equals(sign)) {
                return "sign error";
            }
            if (byOrderId.getAmount().doubleValue() != jsonObject.getBigDecimal("amount").doubleValue()) {
                return "amount is  error";
            }
            int b = platMerOrderService.success(byOrderId);
            if (b > 0) {
                report(byOrderId);
                log.info(" zhaocai success");
                return "ok";
            }
            return "error";

        } catch (RuntimeException ex) {
            log.error("notify EpayException", ex);
            return "error" + ex.getMessage();
        } catch (Exception ex) {
            log.error("notify Excpfpayeption", ex);
            return "system ex ";
        } finally {
            unlock(merchOrder);
        }

    }
    
    
    
    public String wanyun(JSONObject jsonObject) {

        String merchOrder = jsonObject.getString("orderNo");

//        String status = jsonObject.getString("responseState");
        String sign = jsonObject.getString("sign");
//
//        //message
//        jsonObject.remove("sign");
//
//        if (!status.equals("1")) {
//            log.error("plat order is error" + jsonObject.toJSONString());
//            return "plat order status is error";
//        }


        if (StringUtils.isEmpty(merchOrder)) {

            log.error("plat order id is empty" + merchOrder);
            return "plat order id is empty";
        }

        try {
            if (!lock(merchOrder)) {
                return "error";
            }


            PlatMerOrder byOrderId = platMerOrderService.getByOrderId(merchOrder);

            if (StringUtils.equals(byOrderId.getStat(), "2")) {
                return "SUCCESS";
            }

            PlatMer byMerIdCache = platMerService.getByMerIdCache(byOrderId.getMerId());

            if (byMerIdCache == null) {
                return "plat mer is empty not fund";
            }
            jsonObject.remove("sign");
            SortedMap sortedMap = new TreeMap();
            for (String key : jsonObject.keySet()) {
                sortedMap.put(key, jsonObject.getString(key));
            }
            String s = convertUrlNotEmpty(sortedMap, "&", "=")  + byMerIdCache.getPrivateKey();
            log.error(" sign url error {}", s);
//            String sign = SecureUtil.md5(s +"&"+ byMerIdCache.getPrivateKey()).toLowerCase();
            log.error(" sign url error {}", s);
            if (!SecureUtil.md5(s).toLowerCase().equals(sign)) {
                return "sign error";
            }


            if (byOrderId.getAmount().doubleValue() != (jsonObject.getDouble("amount")/100)) {
                return "amount is  error";
            }

            int b = platMerOrderService.success(byOrderId);
            if (b > 0) {


                report(byOrderId);

                return "SUCCESS";
            }
            return "error";

        } catch (RuntimeException ex) {
            log.error("notify EpayException", ex);
            return "error" + ex.getMessage();
        } catch (Exception ex) {
            log.error("notify Exception", ex);
            return "system ex ";
        } finally {
            unlock(merchOrder);
        }
        
    }
    public String damiNew(JSONObject jsonObject) {

        String merchOrder = jsonObject.getString("out_trade_no");

//        String status = jsonObject.getString("responseState");
        String sign = jsonObject.getString("sign");
//
//        //message
//        jsonObject.remove("sign");
//
//        if (!status.equals("1")) {
//            log.error("plat order is error" + jsonObject.toJSONString());
//            return "plat order status is error";
//        }


        if (StringUtils.isEmpty(merchOrder)) {

            log.error("plat order id is empty" + merchOrder);
            return "plat order id is empty";
        }

        try {
            if (!lock(merchOrder)) {
                return "error";
            }


            PlatMerOrder byOrderId = platMerOrderService.getByOrderId(merchOrder);

            if (StringUtils.equals(byOrderId.getStat(), "2")) {
                return "OK";
            }

            PlatMer byMerIdCache = platMerService.getByMerIdCache(byOrderId.getMerId());

            if (byMerIdCache == null) {
                return "plat mer is empty not fund";
            }
            jsonObject.remove("sign");
            SortedMap sortedMap = new TreeMap();
            for (String key : jsonObject.keySet()) {
                sortedMap.put(key, jsonObject.getString(key));
            }
            String s = convertUrlNotEmpty(sortedMap, "&", "=")+"&key="  + byMerIdCache.getPrivateKey();
            log.error(" sign url error {}", s);
//            String sign = SecureUtil.md5(s +"&"+ byMerIdCache.getPrivateKey()).toLowerCase();
            log.error(" sign url error {}", s);
            if (!SecureUtil.md5(s).toUpperCase().equals(sign)) {
                return "sign error";
            }


            if (byOrderId.getAmount().doubleValue() != (jsonObject.getDouble("amount"))) {
                return "amount is  error";
            }

            int b = platMerOrderService.success(byOrderId);
            if (b > 0) {


                report(byOrderId);

                return "OK";
            }
            return "error";

        } catch (RuntimeException ex) {
            log.error("notify EpayException", ex);
            return "error" + ex.getMessage();
        } catch (Exception ex) {
            log.error("notify Exception", ex);
            return "system ex ";
        } finally {
            unlock(merchOrder);
        }

    }
    public String daxiangUrl(JSONObject jsonObject) {
        String merchOrder = jsonObject.getString("orderNo");

        String status = jsonObject.getString("state");
        String sign = jsonObject.getString("sign");

        //message
        jsonObject.remove("sign");

        if (!status.equals("1")) {
            log.error("plat order is error" + jsonObject.toJSONString());
            return "plat order status is error";
        }


        if (StringUtils.isEmpty(merchOrder)) {

            log.error("plat order id is empty" + merchOrder);
            return "plat order id is empty";
        }

        try {
            if (!lock(merchOrder)) {
                return "error";
            }


            PlatMerOrder byOrderId = platMerOrderService.getByOrderId(merchOrder);

            if (StringUtils.equals(byOrderId.getStat(), "2")) {
                return "SUCCESS";
            }

            PlatMer byMerIdCache = platMerService.getByMerIdCache(byOrderId.getMerId());

            if (byMerIdCache == null) {
                return "plat mer is empty not fund";
            }


            String s = jsonObject.getString("state")+byMerIdCache.getMerKey()+
                    jsonObject.getString("orderNo") + jsonObject.getString("amount") +
                    byMerIdCache.getPrivateKey();
            log.error(" sign url error {}", s);
//            String sign = SecureUtil.md5(s +"&"+ byMerIdCache.getPrivateKey()).toLowerCase();
            log.error(" sign url error {}", s);
            if (!SecureUtil.md5(s).toLowerCase().equals(sign)) {
                return "sign error";
            }


            if (byOrderId.getAmount().doubleValue() != jsonObject.getDouble("actualPayAmount")) {
                return "amount is  error";
            }

            int b = platMerOrderService.success(byOrderId);
            if (b > 0) {


                report(byOrderId);
                log.info("success");
                return "success";
            }
            return "error";

        } catch (RuntimeException ex) {
            log.error("notify EpayException", ex);
            return "error" + ex.getMessage();
        } catch (Exception ex) {
            log.error("notify Exception", ex);
            return "system ex ";
        } finally {
            unlock(merchOrder);
        }        }
    public String duijieios(JSONObject jsonObject) {

        String merchOrder = jsonObject.getString("OutMchNbr");

        String status = jsonObject.getString("MsgCode");
        String sign = jsonObject.getString("Sign");

        //message
        jsonObject.remove("Sign");

        if (!status.equals("E0000")) {
            log.error("plat order is error" + jsonObject.toJSONString());
            return "plat order status is error";
        }


        if (StringUtils.isEmpty(merchOrder)) {

            log.error("plat order id is empty" + merchOrder);
            return "plat order id is empty";
        }

        try {
            if (!lock(merchOrder)) {
                return "error";
            }


            PlatMerOrder byOrderId = platMerOrderService.getByOrderId(merchOrder);

            if (StringUtils.equals(byOrderId.getStat(), "2")) {
                return "OK";
            }

            PlatMer byMerIdCache = platMerService.getByMerIdCache(byOrderId.getMerId());

            if (byMerIdCache == null) {
                return "plat mer is empty not fund";
            }
           
            SortedMap sortedMap = new TreeMap();
            for (String key : jsonObject.keySet()) {
                sortedMap.put(key, jsonObject.getString(key));
            }
            String s = convertUrlNotEmpty(sortedMap, "&", "=")+"&key="  + byMerIdCache.getPrivateKey();
            log.error(" sign url error {}", s);
//            String sign = SecureUtil.md5(s +"&"+ byMerIdCache.getPrivateKey()).toLowerCase();
            log.error(" sign url error {}", s);
            if (!SecureUtil.md5(s).toUpperCase().equals(sign)) {
                return "sign error";
            }


            if (byOrderId.getAmount().doubleValue() != (jsonObject.getDouble("Amt"))) {
                return "amount is  error";
            }

            int b = platMerOrderService.success(byOrderId);
            if (b > 0) {


                report(byOrderId);

                return "OK";
            }
            return "error";

        } catch (RuntimeException ex) {
            log.error("notify EpayException", ex);
            return "error" + ex.getMessage();
        } catch (Exception ex) {
            log.error("notify Exception", ex);
            return "system ex ";
        } finally {
            unlock(merchOrder);
        }

    }
}


